define(["angularAMD","moment"], function (angularAMD,moment) {
        angularAMD.service('B0206Service', ['$rootScope', '$filter', '$translate', 'config', 'MMWService', '$mdDialog', "$calculater", '$timeout','$mddProvider',
            function($rootScope, $filter, $translate, config, $MMWService, $mdDialog, $calculater, $timeout,$mddProvider){
                //20221013 modify by 翰鴻 for M#118366
                this.init = function (machine, plot, type, parent, feedback, productList){
                    var nowdatetime = $filter('date')(new Date(), 'yyyy/MM/dd HH:mm:ss');
                    var mode = 'trackOut';
                    var tmpAbnormal_qty = 0;
                    let badType_list=[];
                    var tmpBadReason = [];
                    var badCodeList = {};
                    var badReasonInfo = [];
                    var _labelInfo = [];
    
                    var plotInfo = {}; // plot.info.get
                    var badReasonInfo_backup = [],//不良原因備份
                        labor_detail_backup = [],//多人產量備份
                        production_inf_detail_backup = [], //生產資訊收集
                        sub_product_detail_backup = [], //副產��?
                        machine_no;//生產資訊備份
    
                    if(type=='line'){
                        machine_no = machine.area_no;
                    }else{
                        machine_no = machine.machine_no;
                    }
    
                    var countMethod = "1";
    
                    // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                    var reworkMethod = "1";
                    var reworkMaterialType = "0";
                    //20210519 Modify by德義家興for#90580
                    var op_plugin = false;
                    //20220922 add by 翰鴻 for M#118068
                    var IIoT_Enable = false;
                    if (
                        $.grep(config.module, function (n, i) {
                            return n.name == "moduleIIoT"
                        }).length > 0
                    )
                        IIoT_Enable = true;
                    // 物料用量初始��?
                    function reCalcMaterialUseQty(sum_qty){
                        if(plotInfo.workstation_detail[0] && plotInfo.workstation_detail[0].materials_detail){
                            var materials_detail = plotInfo.workstation_detail[0].materials_detail;
                            var materialsMap = {};
    
                            for(var i = 0; i < materials_detail.length; i++){
                                var materials = materials_detail[i];
    
                                if(!materialsMap[materials.materials_no]){
                                    var materialsList = $filter('filter')(materials_detail, {materials_no: materials.materials_no}, true);
    
                                    if(materialsList.length > 0){
                                        var need_qty = +sum_qty; // 出站所需要的物料用量
                                        
                                        // 20200525 modify by WeiTing for M#72260 - 透過後台傳回參數 Num_Of_Decimal 調整小數點位數，一般是不開放調整的，除非有特殊需求才請後端直接調整資料庫。
                                        var Num_Of_Decimal = +plotInfo.Num_Of_Decimal;
    
                                        // 20201005 modify by WeiTing for M#67681 - 透過後台傳回參數 Close_DecreaseRate，判斷是否關閉損耗率(decrease_rate)計算。
                                        var Close_DecreaseRate = false;
                                        if(plotInfo.Close_DecreaseRate) {
                                            Close_DecreaseRate = true;
                                        }
                                        
                                        materialsList.forEach(function(item, index){
                                            // 物料實際耗用量 = 物料可用量 / 標準用料 / (1 + 損耗量)
                                            var real_use_qty = (((+item.available_qty) / (+item.std_use_qty)) / $calculater.decimalAdd(1, +item.decrease_rate));
                                            if(Close_DecreaseRate){
                                                real_use_qty = ((+item.available_qty) / (+item.std_use_qty));
                                            }
    
                                            if(+real_use_qty < +need_qty){
                                                // 物料預設使用量 = 可用量
                                                use_qty = (+item.available_qty); // 使用量結果
                                                // 20200716 modify by WeiTing for M#74743 - 使用 toFixed 會有四捨五入的問題，所以改用 Math.floor 無條件捨去，才不會造成多扣使用量的問題。
                                                // 20201208 modify by WeiTing for M#82343 - 外包開發的，協助合併回主分支。
                                                item.use_qty = getUseqty(use_qty, Num_Of_Decimal)
                                                need_qty = $calculater.decimalSub(+need_qty, +real_use_qty); // 更新出站所需要的物料用量
                                            } else {
                                                // 物料預設使用量 = 剩餘的物料所需用量 * 標準用量 * (1 + 損耗量)
                                                use_qty = $calculater.decimalMutiple($calculater.decimalMutiple(+need_qty, +item.std_use_qty), $calculater.decimalAdd(1, +item.decrease_rate)); // 使用量結果
                                                if(Close_DecreaseRate){
                                                    use_qty = $calculater.decimalMutiple(+need_qty, +item.std_use_qty); // 使用量結果
                                                }
                                                // 20200716 modify by WeiTing for M#74743 - 使用 toFixed 會有四捨五入的問題，所以改用 Math.floor 無條件捨去，才不會造成多扣使用量的問題。
                                                // 20201208 modify by WeiTing for M#82343 - 外包開發的，協助合併回主分支。
                                                item.use_qty = getUseqty(use_qty, Num_Of_Decimal)
                                                need_qty = 0; // 出站所需要的物料用量已足夠
                                            }
    
                                            // 20200211 modify by WeiTing for M#66921 - 修改扣料順序邏輯：
                                            // 1. 主料存量優先扣除
                                            // 2. 替代料存量依序扣除
                                            // 3. 全部存量扣除完，需求量仍 > 0，則將量加回主料扣除量。（一般料與倒扣料一致）
                                            // 最後，出站所需要的物料用量仍不足夠，將仍不足的量加在第一筆物料(出站才會出現物料不足，不允許出站)
                                            if(index == (materialsList.length - 1) && +need_qty > 0){
                                                need_qty = $calculater.decimalMutiple($calculater.decimalMutiple(+need_qty, +materialsList[0].std_use_qty), $calculater.decimalAdd(1, +materialsList[0].decrease_rate)); 
                                                if(Close_DecreaseRate){
                                                    need_qty = $calculater.decimalMutiple(+need_qty, +materialsList[0].std_use_qty);
                                                }
                                                use_qty = $calculater.decimalAdd(+materialsList[0].use_qty, +need_qty); // 使用量結果
                                                // 20200716 modify by WeiTing for M#74743 - 使用 toFixed 會有四捨五入的問題，所以改用 Math.floor 無條件捨去，才不會造成多扣使用量的問題。
                                                // 20201208 modify by WeiTing for M#82343 - 外包開發的，協助合併回主分支。
                                                materialsList[0].use_qty = getUseqty(use_qty, Num_Of_Decimal)
                                            }
                                        });
                                    }
                                    materialsMap[materials.materials_no] = true;
                                }
                            }
                            //M#96594 add by a991241234 修正重工批號  reworkMethod = 2 將物料使用量歸零
                            if(reworkMethod && reworkMethod == "2" && reworkMaterialType && reworkMaterialType ==  "1"){
                                plotInfo.workstation_detail[0].materials_detail.forEach(item => {
                                    item.use_qty = 0;
                                });
                            }
                        }
                    }
    
                    // 20201208 modify by WeiTing for M#82343 - 外包開發的，協助合併回主分支。
                    function getUseqty(uer_qty, Num_Of_Decimal){
                        if(countMethod == "1"){
                          return  Math.floor(+use_qty * Math.pow(10, +Num_Of_Decimal)) / Math.pow(10, +Num_Of_Decimal); // 調整使用量結果的小數點位數
                        }else if(countMethod == "2"){
                          return Math.ceil(+use_qty * Math.pow(10, +Num_Of_Decimal)) / Math.pow(10, +Num_Of_Decimal); 
                        }else if(countMethod == "3"){
                           return Math.round(+use_qty * Math.pow(10, +Num_Of_Decimal)) / Math.pow(10, +Num_Of_Decimal); 
                        }else{
                           return evenRound(use_qty, Num_Of_Decimal);
                        }
                    }
    
                    // 20201208 modify by WeiTing for M#82343 - 外包開發的，協助合併回主分支。
                    function evenRound(num, decimalPlaces) {   
                        var d = decimalPlaces || 0;
                        var m = Math.pow(10, d);
                        var n = +(d ? num * m : num).toFixed(8); // Avoid rounding errors
                        var i = Math.floor(n), f = n - i;
                        var e = 1e-8; // Allow for rounding errors in f
                        var r = (f > 0.5 - e && f < 0.5 + e) ?
                                    ((i % 2 == 0) ? i : i + 1) : Math.round(n);
                        return d ? r / m : r;
                    }
    
                    //取得生產批資��?
                    function getInitInfo(continued) {
                        var content = {
                            machine_no : machine_no,
                            plot_no: plot.plot_no,
                            op_seq : '',//
                            op_no :plot.op_no,
                            workstation_no:'',//
                            qty: '',
                            return_type:'2',
                            op_plug_in: plot.op_plug_in
                        };
                        if(parent == 'B0214'){
                            content.mode = '1';
                        }
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.plot_info_get',
                            content: content,
                            success: function (data) {
                                // 20201208 modify by WeiTing for M#82343 - 外包開發的，協助合併回主分支。
                                if (data.CountMethod){
                                    countMethod = data.CountMethod;
                                }
                                
                                // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                                if(data.auto_rework_material_process){
                                    reworkMethod = data.auto_rework_material_process;
                                }
    
                                if (data.plot_info_get.length > 0) {
                                    plotInfo = data.plot_info_get[0];
                                    // 20210104 modify by 外包Nick.Lin for M#85092: 新增系统参数
                                    plotInfo.workstation_detail[0].materials_detail.forEach(function(item){
                                        item.deduction_method = item.deduction_method;
                                    });
                                    checkLaborDetail(plotInfo, data,continued)
                                } else {
                                    $rootScope.showAlert('plot_info_get is empty');
                                }
                                
                            }
                        });
                    };
                    //人員計價 出站 總額計算 add by a991241234 for M# 70310
                    function getPriceSum()
                    {
                        var price_check_1 = isNaN(parseInt(plotInfo.price_type)) == false;
                        var price_check_2 = isNaN(parseFloat(plotInfo.price)) == false;
                        if(price_check_1 && price_check_2)
                        {
                            switch(plotInfo.price_type)
                            {
                                //計件
                                case "0":
                                    if(isNaN(parseFloat(plotInfo.qty)) == false)
                                    plotInfo.price_sum = parseFloat(plotInfo.qty) * parseFloat(plotInfo.price);
                                break;
                                //計時
                                case "1":
                                    if(isNaN(parseFloat(plotInfo.workstation_detail[0].labor_hours)) == false)
                                    plotInfo.price_sum = parseFloat(plotInfo.workstation_detail[0].labor_hours) * parseFloat(plotInfo.price);
                                break;
                            }
                        }
                    }
                    //人員計價 多人量產 總額計算 add by a991241234 for M# 70310
                    function getPriceSumByLabor()
                    {
                        var price_check_1 = isNaN(parseInt(plotInfo.price_type)) == false;
                        var price_check_2 = isNaN(parseFloat(plotInfo.price)) == false;
                        var price_check_3 = plotInfo.workstation_detail[0].labor_detail.length > 0;
                        if(price_check_1 && price_check_2 && price_check_3)
                        {
                            switch(plotInfo.price_type)
                            {
                                //計件
                                case "0":
                                    var sum = 0;
                                    for(var i in plotInfo.workstation_detail[0].labor_detail)
                                    {
                                        var qty;
                                        if(isNaN(parseFloat(plotInfo.workstation_detail[0].labor_detail[i].qty)) == false)
                                            qty = plotInfo.workstation_detail[0].labor_detail[i].qty;
                                        else
                                            qty = plotInfo.workstation_detail[0].labor_detail[i].labor_qty;
                                        plotInfo.workstation_detail[0].labor_detail[i].price_sum = parseFloat(plotInfo.price) * parseFloat(qty);
                                        sum +=plotInfo.workstation_detail[0].labor_detail[i].price_sum;
                                    }
                                    if(sum > 0)
                                        //20221118 modify by wangqq for M#0120448:修正字符串转换错误
                                        plotInfo.price_sum = Number(sum).toFixed(2);
                                break;
                                //計時
                                case "1":
                                    var sum = 0;
                                    for(var i in plotInfo.workstation_detail[0].labor_detail)
                                    {
                                        var time = plotInfo.workstation_detail[0].labor_detail[i].labor_time;
                                        plotInfo.workstation_detail[0].labor_detail[i].price_sum = parseFloat(plotInfo.price) * parseFloat(time);
                                        sum +=plotInfo.workstation_detail[0].labor_detail[i].price_sum;
                                    }
                                    if(sum > 0)
                                        plotInfo.price_sum = Number(sum).toFixed(2);
                                break;
                            }
                        }
                    }
                    //回到出站畫面
                    function backToTrackOut(dialog){
                        if(dialog.mode == 'badReason'){
                            dialog.badReasonInfo = badReasonInfo_backup.slice();
                            badReasonInfo_backup = [];
                            dialog.tmpBadReason = '';
                            dialog.tmpAbnormal_qty = '';
                        } else if(dialog.mode == 'multiple'){
                            dialog.plotInfo.workstation_detail[0].labor_detail = angular.merge([],labor_detail_backup);
                            labor_detail_backup = [];
                            dialog.tmpLabor_no = '';
                        } else if(dialog.mode == 'production_inf'){
                            dialog.plotInfo.production_inf_detail = angular.merge([],production_inf_detail_backup);
                            production_inf_detail_backup = [];
                        } else if(dialog.mode == 'sub_product'){
                            dialog.plotInfo.sub_product_detail = angular.merge([],sub_product_detail_backup);
                            sub_product_detail_backup = [];
                        //20210519 Modify by德義家興for#90580
                        } else if (dialog.mode == 'PCSNo') {
                            if (dialog.PCSNoList_count >= 1) {
                                dialog.update_PlotInfo_Qty();
                            }
                        } else if (dialog.mode == 'newBadReason') {
                            dialog.badReasonInfo = badReasonInfo_backup.slice(); //複製給
                            badReasonInfo_backup = []; //備份清空
                            dialog.tmpBadReason = '';
                            dialog.tmpAbnormal_qty = '';
                        }
                        //如果是在新例外原因畫面點選回前頁,回到序列號收集
                        if (dialog.mode == 'newBadReason') {
                            dialog.mode = 'PCSNo';
                            // 20230303 modify by Alan for M#128535: 補上缺少功能
                            dialog.changeForm('B0206_Serial_Number_Collecte');
                        }else{ //其他都回出站畫面
                            dialog.mode = 'trackOut';
                        }
                    }
    
                    //出站確認
                    function trackOutConfirm(dialog,child_dialog) {
                        var abnormal_detail = [],
                            plot_info_detail= {},
                            materials_detail=[],
                            subop_employee_detail=[],
                            sub_product_detail=[];
                        //不良原因
                        dialog.badReasonInfo.forEach(function (item) {
                            abnormal_detail.push({
                                abnormal_no:item.abnormal_no,
                                defect_qty:item.defect_qty,
                                reason_type:item.reason_type,
                                //20210519 Modify by德義家興for#90580
                                pcs_no: item.pcs_no
    
                            });
                        });
                        if(dialog.parent != 'B0214'){
                            dialog.plotInfo.workstation_detail[0].labor_detail.forEach(function(item){
                                subop_employee_detail.push({
                                    employee_no:item.labor_no,
                                    work_time:item.labor_time,
                                    qty:item.qty,
                                    parameter_value: item.ParameterValue
                                });
                            });
                        }
                        //物料
                        dialog.plotInfo.workstation_detail[0].materials_detail.forEach(function(item){
                            // 20200211 modify by WeiTing for M#66921 - 倒扣料本來不回送資料，現在跟一般料一樣，都需要回送資料。
                            // if(item.putinplace_type == '5' && item.material_opt == '0')
                            //     return;
    
                            materials_detail.push({
                                materials_no: item.sub_materials_no,
                                materials_plot_no: item.materials_plot_no,
                                actual_use_qty: item.use_qty,                            
                            });
                        });
                        //副產��?
                        if(dialog.plotInfo.sub_product_detail){
                            dialog.plotInfo.sub_product_detail.forEach(function(item){
                                if((+item.sub_product_qty) == 0)
                                    return;
    
                                sub_product_detail.push(item);
                            });
                        }
                        //人員計價 add by a991241234 for M# 70310
                        var price_rate_list = [];
                        for(var i in dialog.plotInfo.workstation_detail[0].labor_detail)
                        {
                            var price_rate_obj = {};
                            price_rate_obj.acc = dialog.plotInfo.workstation_detail[0].labor_detail[i].labor_no;
                            price_rate_obj.price_rate = dialog.plotInfo.workstation_detail[0].labor_detail[i].PriceRate;
                            price_rate_list.push(price_rate_obj);
                        }
    
                        var op_plug_in_detail = [{
                            op_plug_in: dialog.op_plug_in,
                            heat_plot_no: dialog.heat_plot_no
                        }];
    
                        plot_info_detail = {
                            report_datetime : dialog.plotInfo.sysdate_time,
                            machine_no : machine_no, //
                            plot_no : dialog.plotInfo.workstation_detail[0].plot_no,
                            op_seq : dialog.plotInfo.workstation_detail[0].op_seq,
                            op_no : dialog.plotInfo.workstation_detail[0].op_no,
                            workstation_no : '',
                            qty:dialog.plotInfo.qty,//20180418 modify by Dustdusk for 調整回傳數量，一律改為使用者輸入的數量
                            labor_hours : dialog.plotInfo.workstation_detail[0].labor_hours,
                            machine_hours : dialog.plotInfo.workstation_detail[0].machine_hours,
                            number_of_operators : dialog.plotInfo.workstation_detail[0].number_of_labor,//
                            plot_stamp : dialog.plotInfo.workstation_detail[0].plot_stamp,
                            //20190617 modify by Dustdusk for M#: 增加回傳產品編號
                            product_no: dialog.plotInfo.product_no,
                            // 20211208 modify by chenshibo for#104361: [sMES]plot_check_out_process 服務無法取得產品版本[成綸]
                            product_ver: dialog.plotInfo.product_ver,
                            process_no : dialog.plotInfo.process_no,
                            process_ver : dialog.plotInfo.process_ver,
                            abnormal_detail : abnormal_detail,
                            subop_employee_detail : subop_employee_detail,
                            materials_detail : materials_detail,
                            wait_reason_detail : dialog.plotInfo.wait_reason_detail,
                            //20190821 modify by Dustdusk for M#61331: 增加回傳副產��?
                            sub_product_detail : sub_product_detail,
                            //20190821 modify by Dustdusk for M#62692: 增加回傳扣件資訊
                            fastening_info_detail:dialog.plotInfo.fastening_info_detail,
                            // 20200225 modify by WeiTing for M#67404: 注塑模組 - 增加回傳 模次(cavity_number) 和 穴數(run_counter)。
                            cavity_number: dialog.plotInfo.workstation_detail[0].cavity_number,
                            run_counter: dialog.plotInfo.workstation_detail[0].run_counter,
                            //add by a991241234 for M# 70310 人員計價
                            price:dialog.plotInfo.price,
                            price_type:dialog.plotInfo.price_type,
                            price_rate_list:price_rate_list,
                            op_plug_in_detail: op_plug_in_detail,
                            defect_qty : dialog.plotInfo.total_abnormal_qty,
                            lack_qty : dialog.plotInfo.total_lack_qty,//20200604 新增短少與不良數回下一頁
                            good_qty:dialog.plotInfo.good_qty // 20231229 modify by shiwl for M#  0153822: MES6.0,出站自动打印，根据产品基本资料中的最小包装数，打印标签，出站的数量
                        };
                        // 20210120 modify by 外包 for M#69327: 加入產線content
                        var line_content = {};
                        var plan_work = {
                            date: nowdatetime.split(' ')[0],
                            time: nowdatetime.split(' ')[1]
                        };
                        var work_time = $filter('date')(plan_work.date, 'yyyy/MM/dd') + " " + plan_work.time;
                        line_content = {
                            machine_no: machine.area_no,
                            report_datetime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
                            machine_status: '1',
                            remark: '',
                            handle_user_no: config.cache.account,
                            plan_start_time: plot.machine_status == '0' || plot.machine_status == '1' ? '' : work_time,
                            actual_end_time: plot.machine_status == '0' || plot.machine_status == '1' ? work_time : '',
                            remarks: undefined
                        };
                        //20210519 Modify by德義家興for#90580
                        var tempPCSNo = [];
                        dialog.PCSNoList.forEach(function(item){
                            tempPCSNo.push(item.pcs_no);
                        });
    
                        var content = {
                            //20210519 Modify by德義家興for#90580
                            pcs_no: tempPCSNo,
                            collection_type: '1', //進站'0',出站'1'
                            got_pcs_no: dialog.PCSNoHasBadReason, //是否走序列號收集的邏輯
    
                            //20210519 Modify by德義家興for#90580
                            pcs_no: tempPCSNo,
                            collection_type: '1', //進站'0',出站'1'
                            //20210615 Modify by德義家興for#90580:除了true都給false
                            got_pcs_no: (dialog.PCSNoHasBadReason != true ? false : true), //是否走序列號收集的邏輯
    
                            report_datetime: plot_info_detail.report_datetime,
                            check_out_mode: '1',
                            check_out_type: '2',
                            plot_info_detail:[plot_info_detail],
                            label_no: dialog.plotInfo.label_no,
                            production_inf_type : dialog.plotInfo.production_inf_type,
                            production_inf_detail:dialog.plotInfo.production_inf_detail,
                            force_check_out:dialog.force_check_out,
                            force_account:dialog.force_account,
                            force_password:dialog.force_password
                        };
                        //20220922 add by 翰鴻 for M#118068
                        //M#91613 [IIoT]
                        if (IIoT_Enable && plot.need_prod_change)
                            content.need_prod_change = plot.need_prod_change;
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.plot_check_out_process',
                            content: content,
                            success: function (data, response) {
                                // 20201015 modify by WeiTing for M#77484: 有自動分批(auto_msg_list)情況時，跳自動分批訊息。
                                if(data.auto_msg_list && data.auto_msg_list.length > 0){
                                    $rootScope.showToast(data.auto_msg_list[0]);
                                } else {
                                    $rootScope.showToast(response.Message);
                                }
                                //20200103 add by Dustdusk for M#66703: 增加出站後呼叫bartender
                                $timeout(function () {
                                    // 20201015 modify by WeiTing for M#77484: 如果原本的 batender 和 pdf 列印沒資料時，跳自動分批的列印效果(auto_runcard_pdf_get)。
                                    if (data.command_lines && data.command_lines.length > 0 || data.runcard_pdf_get && data.runcard_pdf_get.length > 0) {
                                        // 執行標籤列印
                                        if (data.command_lines && data.command_lines.length > 0) {
                                            printLabel(0, data.command_lines);
                                        }
                                        // 執行 PDF列印
                                        if (data.runcard_pdf_get && data.runcard_pdf_get.length > 0) {
                                            // 20201121 modify by 外包 for M#80272: 增加不同的标签可以多条打印的功能
                                            let tempRuncardPdf = [];
                                            data.runcard_pdf_get.forEach(r => {
                                                if (r.printCount > 1) {
                                                    for (var i = 0; i < r.printCount; i++) {
                                                        tempRuncardPdf.push({
                                                            url_pdf: r.url_pdf,
                                                            width: r.width,
                                                            height: r.height,
                                                            printCount: 1
                                                        });
                                                    }
                                                } else {
                                                    tempRuncardPdf.push(r);
                                                }
                                            });
                                            printBatch(tempRuncardPdf, 0);
                                        }
                                    } else {
                                        // 自動打印
                                        if (data.auto_runcard_pdf_get && data.auto_runcard_pdf_get.length > 0) {
                                            // 20201110 modify by WeiTing for M#80602 - 增加多張列印功能(printCount)。
                                            for (var i = 0; i < data.auto_runcard_pdf_get.length; i++) {
                                                pdf_url = data.auto_runcard_pdf_get[0].url_pdf;
                                                if (pdf_url.indexOf('http://') == -1) {
                                                    pdf_url = 'http://' + config.server.ip + ':' + config.server.port + pdf_url;
                                                }
                                                print(pdf_url, 1);
                                            }
                                        }
                                    }
                                }, 200);
                                if(dialog.continued)
                                {
                                    dialog.hide();
                                    getInitInfo(dialog.continued);
                                }
                                else
                                    dialog.hide();
                                    if(child_dialog)child_dialog.hide();
    
                                //20220511 add by 翰鴻 for M#102965、110964 换刀批量产品出站后自动进入上下具界面                            
                                changeBladeCheckAndLoadAccessory(dialog.plotInfo.workstation_detail[0].plot_no, dialog.plotInfo.workstation_detail[0].op_no);
    
                                if(feedback)
                                    feedback(line_content);
                            }
                        });
                    }
    
                    // 批量打印
                    function printBatch(runcard_pdf_get, index) {
                        if (index < runcard_pdf_get.length) {
                            pdf_url = runcard_pdf_get[index].url_pdf;
                            if (pdf_url.indexOf('http://') == -1) {
                                pdf_url = 'http://' + config.server.ip + ':' + config.server.port + pdf_url;
                            }
                            var width = runcard_pdf_get[index].width;
                            var height = runcard_pdf_get[index].height;
                            printNotSameBarcode(pdf_url, width, height, function callback() {
                                index = index + 1;
                                printBatch(runcard_pdf_get, index);
                            });
    
                        }
                    };
    
                    // PDF列印
                    function printNotSameBarcode(pdf_url, width, height, callback) {
                        if (window.nodeRequire) {
                            // 20220730 modify by chenshibo for#113135：增加支援外部打印
                            if (config.setting.outsidePDF == 'Y') {
                                var fs = window.nodeRequire('fs'), RuncardPath;
                                try {
                                    // 20240321 modify by Alan for#159805 : electron升級後，兼容新舊版本
                                    const remote = window.nodeRequire('electron').remote || window.nodeRequire('@electron/remote');
                                    RuncardPath = remote.app.getAppPath();
                                } catch (e) {
                                    RuncardPath = window.nodeRequire('path').dirname(process.execPath) + '\\package.nw';
                                }
                                RuncardPath += '\\www\\Runcard';
                                if (!fs.existsSync(RuncardPath)) {
                                    fs.mkdirSync(RuncardPath);
                                }

                                // 20240222 add by Alan for#158151 : 清除Runcard目錄下未開啟的舊檔案
                                // 20240408 modify by Alan for#139948 : 改成同步讀取，避免刪除檔案後立即列印造成找不到檔案
                                fs.readdirSync(RuncardPath, (err, files) => {
                                    if (err) {
                                        console.log(err);
                                    }
                                    //listing all files using forEach
                                    files.forEach((file) => {
                                        // Do whatever you want to do with the file
                                        fs.unlink(RuncardPath + '/' + file, (err) => {
                                            if (err) {
                                                console.debug(err);
                                            }
                                        })
                                    });
                                })
            
                                // 20240222 add by Alan for#158151 : 增加時間戳記，避免檔名重複造成檔案開啟時無法寫入
                                let pdfPath = `${RuncardPath}/RuncardPreview_${Date.now()}.pdf`;
                                $rootScope.downloadFile(pdf_url, pdfPath, function (dist_path) {
                                    $rootScope.showLoading();
                                    window.nodeRequire('child_process').exec('@powershell "start -verb print ""' + dist_path + '"""', (err, stdout, stderr) => {
                                        if (err) {
                                            $rootScope.hideLoading();
                                            // 20240223 modify by Alan for#158194 : 優化錯誤提示
                                            $rootScope.showAlert($filter('translate')('error.print_failed_please_check_is_Acrobat_Reader_installed'), { level: 'warning', });
                                            console.error(err);
                                        }
                                        else {
                                            callback();
                                            $rootScope.hideLoading();
                                            $rootScope.showToast($filter('translate')('common.msg.success'));
                                        }
                                    });
                                });
                            } else {
                                var sumatraPDF = window.nodeRequire('sumatra-pdf');
                                if (sumatraPDF) {
                                    var fs = window.nodeRequire('fs'), RuncardPath;
                                    try {
                                        // 20240321 modify by Alan for#159805 : electron升級後，兼容新舊版本
                                        const remote = window.nodeRequire('electron').remote || window.nodeRequire('@electron/remote');
                                        RuncardPath = remote.app.getAppPath();
                                    } catch (e) {
                                        RuncardPath = window.nodeRequire('path').dirname(process.execPath) + '\\package.nw';
                                    }
                                    RuncardPath += '\\www\\Runcard';
                                    if (!fs.existsSync(RuncardPath)) {
                                        fs.mkdirSync(RuncardPath);
                                    }

                                    // 20240222 add by Alan for#158151 : 清除Runcard目錄下未開啟的舊檔案
                                    // 20240408 modify by Alan for#139948 : 改成同步讀取，避免刪除檔案後立即列印造成找不到檔案
                                    fs.readdirSync(RuncardPath, (err, files) => {
                                        if (err) {
                                            console.log(err);
                                        }
                                        //listing all files using forEach
                                        files.forEach((file) => {
                                            // Do whatever you want to do with the file
                                            fs.unlink(RuncardPath + '/' + file, (err) => {
                                                if (err) {
                                                    console.debug(err);
                                                }
                                            })
                                        });
                                    })
                
                                    // 20240222 add by Alan for#158151 : 增加時間戳記，避免檔名重複造成檔案開啟時無法寫入
                                    let pdfPath = `${RuncardPath}/RuncardPreview_${Date.now()}.pdf`;
                                    $rootScope.downloadFile(pdf_url, pdfPath, function (dist_path) {
                                        $rootScope.showLoading();
                                        // 20201110 modify by WeiTing for M#80602 - 不跳列印介面，直接使用預設列印機進行列印(printToDefault)。
                                        var _fn = sumatraPDF.printToDefault;
                                        _fn({
                                            path: dist_path,
                                            settings: width > height ? 'landscape' : '',
                                            success: function () {
                                                callback();
                                                $rootScope.hideLoading();
                                                $rootScope.showToast($filter('translate')('common.msg.success'));
                                            },
                                            error: function (error) {
                                                $rootScope.hideLoading();
                                                $rootScope.showToast($filter('translate')('common.msg.success'));
                                            }
                                        });
                                    });
                                } else {
                                    window.frames['kmi-pdf-panel'].pdf_print();
                                }
                            }
                        } else {
                            window.frames['kmi-pdf-panel'].pdf_print();
                        }
                    };
                    
                    //檢查出站資訊
                    function ProductionParametersCheckProcess(dialog){
                        var defect_qty = 0;
                        dialog.badReasonInfo.forEach(function (item) {
                            if(item.abnormal_type != '11'){
                                //2018051601 modify by Dustdusk for M#45925: 調整良品不良品計算規��?
                                defect_qty = defect_qty + (+item.defect_qty);
                            }
                        });
                        var content = {
                            handle_type : 'CHECK_OUT',
                            recordlist : [{
                                plot_no : dialog.plotInfo.workstation_detail[0].plot_no,
                                op_no : dialog.plotInfo.workstation_detail[0].op_no,
                                qty : dialog.plotInfo.qty,//20180418 modify by Dustdusk for 調整回傳數量，一律改為使用者輸入的數量
                                abnormal_detail:plotInfo.workstation_detail[0].abnormal_detail
                            }]
                        };
    
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.production_parameters_check_process',
                            content: content,
                            success: function (data) {
                                // 20200619 add by Oliver 送出成功后把dialog.plotInfo.qty紀錄進localstorage
                                if(dialog.checkOutQty_record.length===20){//如果數量超過20則清掉
                                    dialog.checkOutQty_record=[];
                                    dialog.plotInfo.has_this_data='';
                                }
                                if(typeof(dialog.plotInfo.has_this_data)==='number'){//如果localstorage內已有這筆資料，則修改這筆資料內的數字。
                                   dialog.checkOutQty_record[dialog.plotInfo.has_this_data].record_qty = dialog.plotInfo.qty;
                                }else{//如果沒有，就寫一個新的。
                                    let output_record = { lot_no:dialog.plotInfo.workstation_detail[0].plot_no, op_no:dialog.plotInfo.workstation_detail[0].op_no, record_qty:dialog.plotInfo.qty};
                                    dialog.checkOutQty_record.push(output_record);
                                }
                                localStorage.setItem('checkOutQtyRecord',JSON.stringify(dialog.checkOutQty_record));
                                checkRule(data.query_result, dialog);
                            }
                        });
                    }
    
                    //根據結果結果呈現
                    //rule_result : WARNNING / WAIT / PASS
                    //20170517 modify by Dustdusk for SMES_ProductionParametersCheckProcess調整回傳內容
                    function checkRule(query_result, dialog){
                        var warnning_msg = '';
                        query_result.forEach(function(plot_rule){
                            var plot_warnning_msg = '';
                            plot_rule.rule_detail.forEach(function(rule_detail){
                                if(rule_detail.rule_result == 'WARNNING'){
                                    if(plot_warnning_msg == ''){
                                        plot_warnning_msg = plot_rule.plot_no + '<br>';
                                    }
                                    plot_warnning_msg += rule_detail.rule_message + '<br>';
                                } else if(rule_detail.rule_result == 'WAIT'){
                                    //is_wait = true;
                                    if(plot_warnning_msg == ''){
                                        plot_warnning_msg = plot_rule.plot_no + '<br>';
                                    }
                                    plot_warnning_msg += rule_detail.rule_message + '<br>';
                                    //dialog.plotInfo.wait_reason_detail.push({reason_no:'Z901'});
                                }
                            });
                            warnning_msg += plot_warnning_msg;
                        });
    
                        if(warnning_msg != ''){
                            $rootScope.showConfirm(warnning_msg,
                                function(confirm_dialog){
    
                                    confirm_dialog.hide();
                                    //20211112 modify by 翰鴻 for M#103006 BEG
                                    
                                    var exist = 'N'
                                    query_result[0].rule_detail.forEach(function ( rule_detail) {
                                        if (rule_detail.rule_no === "RULE_YIELD_LCL") {
                                            if (rule_detail.rule_result !== "PASS")
                                                exist = 'Y';                                        
                                        }                                    
                                    });
                                    if (exist === 'N') {
                                        trackOutConfirm(dialog);
                                    }
                                    else {
                                        //異常良率強制出站
                                        CheckOutDialog(dialog);
                                    }
                                    
                                    //20211112 modify by 翰鴻 for M#103006 END
                                    
                                    //trackOutConfirm(dialog);
                                }
                            )
                        } else {
                            trackOutConfirm(dialog);
                        }
                    }
    
                    //取得例外原因類別
                    function genBadType(badReasonList, ori_badReasonList){
                        var badTypeList = {},
                            return_list = [];
                        //如果已經有設定不良原因,要記錄已設定的
                        ori_badReasonList.forEach(function (badReason) {
                            var temp = $filter('filter')(badReasonList, { reason_no: badReason.abnormal_no }, true);
                            if (temp.length > 0) {
                                temp[0].chosen = 'Y';
                            }
                        });
                        badReasonList.forEach(function (badReason) {
                            if (badTypeList[badReason.reason_type]) { //已有不良原因type, 放進badReason_list
                                badTypeList[badReason.reason_type].badReason_list.push(badReason);
                            } else { //找到新的不良原因type, 加入badTypeList
                                badTypeList[badReason.reason_type] = {
                                    reason_type:badReason.reason_type,
                                    reason_sub_type:badReason.reason_sub_type,
                                    badReason_list:[badReason]
                                }
                            }
                        });
        
                        return $rootScope.getValueforObj(badTypeList);
                    }
                    // 取出不良原因
                    function BadReasonPick(badTypeList, reason_no){
                        for (var i = 0; i < badTypeList.length;i++){
                            var _temp = $filter('filter')(badTypeList[i].badReason_list, {reason_no:reason_no}, true);
                            if(_temp.length > 0){
                                return _temp[0];
                            }
                        };
                    }
    
                    //轉換率計��?
                    function CaculatQTYACIO(qty, C_Numerator, C_Denominator){
                        var QTYACIO = $calculater.decimalMutiple((+qty), (+C_Numerator)),
                            C_Mode = plotInfo.workstation_detail[0].C_Mode,
                            C_Accuracy = Math.pow(10, plotInfo.workstation_detail[0].C_Accuracy || 0) || 1;
                        //20240410 modify by wangzy for M#0154345: [sMES] 出站畫面的轉換後出站數量顯示異常 [民景]
                        QTYACIO = $calculater.decimalDivide(QTYACIO, (+C_Denominator));
                        if(C_Mode == '0'){
                            //無條件進位
                            QTYACIO = Math.ceil(QTYACIO * C_Accuracy) / C_Accuracy;
                        } else if(C_Mode == '1'){
                            //無條件捨��?
                            QTYACIO = Math.floor(QTYACIO * C_Accuracy) / C_Accuracy;
                        }
                        return QTYACIO;
                    }
    
                    //扣件行業雙單位計��?
                    function CaculateFastening(fastening_info, qty){
                        var _qty = $calculater.decimalMutiple($calculater.decimalSub(qty, fastening_info.vehicle_weight||0), (fastening_info.molecule||1)) / (fastening_info.denominator||1),
                            _accuracy = Math.pow(10, fastening_info.accuracy||0)||1;;
                        if(fastening_info.conversion_rules == 0){
                            //無條件進位
                            _qty = Math.ceil(_qty * _accuracy) / _accuracy;
                        } else if(fastening_info.conversion_rules == 1){
                            //無條件捨��?
                            _qty = Math.floor(_qty * _accuracy) / _accuracy;
                        } else if(fastening_info.conversion_rules == 2){
                            //四捨五入
                            _qty = Math.round(_qty * _accuracy) / _accuracy;
                        }
                        return _qty;
                    }
    
                    //確認是否需要多人產量登入數量重��?
                    function reCalcMultipleQty(dialog, callback){
                        if(dialog.OutQtyOption == '1' || dialog.OutQtyOption == '2'){
                            //出站數量有異動，是否要重計多人產量登入數��?
                            $rootScope.showConfirm($filter('translate')('B0206.msg.is_recalculate_multiple_qty'), function(confirmDialog){
                                confirmDialog.hide();
                                multipleRecalculateImp(dialog, function(){
                                    if (callback)
                                        callback();
                                });
                            }, function(confirmDialog){
                                confirmDialog.hide();
                                if (callback)
                                    callback();
                            });
                        } else if(dialog.OutQtyOption == '3'){
                            var max_labor_qty = 0;
                            dialog.plotInfo.workstation_detail[0].labor_detail.forEach(function(labor){
                                if(max_labor_qty < labor.qty){
                                    max_labor_qty = labor.qty;
                                }
                            });
    
                            if(dialog.plotInfo.workstation_detail[0].QTYACIO < max_labor_qty){
                                $rootScope.showAlert($filter('translate')('B0206.msg.chkout_ls_multiple_qty')); //出站數量小於多人產量登入數量，請重新維護��?
                                multipleRecalculateImp(dialog, function(){
                                    if (callback)
                                        callback();
                                });
                            } else {
                                if (callback)
                                    callback();
                            }
                        } else {
                            multipleRecalculateImp(dialog, function(){
                                if (callback)
                                    callback();
                            });
                        }
                    }
    
                    //多人產量登入數量重計
                    function multipleRecalculateImp(dialog, callback){
                        var QTYACIO = dialog.plotInfo.workstation_detail[0].QTYACIO; //出站後數��?出站-不良-短少+多餘)
                        var labor_detail = dialog.plotInfo.workstation_detail[0].labor_detail;
                        let good_qty = dialog.plotInfo.good_qty;
                        if(dialog.OutQtyOption == '0'){
                            //0: 預設(每人數量=出站數量)
                            if (labor_detail && labor_detail.length > 0) {
                                for (var index = 0; index < labor_detail.length; index++) {                           
                                    labor_detail[index].qty = good_qty;
                                }
                            }
                            //multipleRecalculate(QTYACIO,labor_detail, function (index, assigned_qty) {
                            //    return QTYACIO;
                            //});20210903 modi for M#99015
                        }else if(dialog.OutQtyOption == '1'){
                            // 1: 均分(每人數量 = 出站數量/人員總數)
                            multipleRecalculate(good_qty,labor_detail, function (index, assigned_qty) {
                                if(index < (labor_detail.length - 1)){
                                    return Math.floor(good_qty / labor_detail.length);
                                } else {
                                    return $calculater.decimalSub(good_qty, assigned_qty); //剩下未分配的數量全塞給最後一��?
                                }
                            });
                        } else if(dialog.OutQtyOption == '2'){
                            // 2: 按在線時間分��?每人數量 = 出站數量*人員工時/總人��?
                            var total_labor_time = 0; //總人��?
                            labor_detail.forEach(function(labor){
                                total_labor_time = $calculater.decimalAdd(total_labor_time, labor.labor_time);
                            });
                            labor_detail = $filter('orderBy')(dialog.plotInfo.workstation_detail[0].labor_detail, 'labor_time'); //用工時排序，確保工時多的人排在最��?
    
                            if(total_labor_time > 0){
                                multipleRecalculate(good_qty,labor_detail, function (index, assigned_qty) {
                                    if(index < (labor_detail.length - 1)){
                                        return Math.floor($calculater.decimalMutiple(good_qty, labor_detail[index].labor_time) / total_labor_time);
                                    } else {
                                        return $calculater.decimalSub(good_qty, assigned_qty); //剩下未分配的數量全塞給最後一��?
                                    }
                                });
                            } else {
                                //工時總和=0，採用均分(每人數量 = 出站數量/人員總數)
                                multipleRecalculate(good_qty,labor_detail, function (index, assigned_qty) {
                                    if(index < (labor_detail.length - 1)){
                                        return Math.floor(good_qty / labor_detail.length);
                                    } else {
                                        return $calculater.decimalSub(good_qty, assigned_qty); //剩下未分配的數量全塞給最後一��?
                                    }
                                });
                            }
                        } else if(dialog.OutQtyOption == '3'){
                            // 3: 全手動輸入(每人數量 = 0)
                            multipleRecalculate(good_qty,labor_detail, function (index, assigned_qty) {
                                return 0;
                            });
                        }
                        if (callback)
                            callback();
                    }
                    //多人產量登入數量重計
                    function multipleRecalculate(QTYACIO, labor_detail, getQty) {
                        var qty = 0; // 每人分到的數量
                        var assigned_qty = 0; //已分配的數量
    
                        if (labor_detail && labor_detail.length > 0) {
                            //20210310 Modify by chenshibo for#89117：均分出站量，上工4个人，出站2件，出站时多人产量默认为1，1,1，-1
                            for (var index = 0; index < labor_detail.length; index++) {
                                if (QTYACIO <= assigned_qty) {
                                    qty = 0;
                                }
                                else {
                                    qty = getQty(index, assigned_qty);
                                }
                                labor_detail[index].qty = qty;
                                assigned_qty = $calculater.decimalAdd(assigned_qty, qty);
                            }
                        }
                    }
    
                    // 扣件資訊檢查 / 多人產量登入檢查
                    function multipleCheck(dialog, callback){
                        var msg = '', warring_msg = '';
                        var labor_detail = dialog.plotInfo.workstation_detail[0].labor_detail;
                        var total_labor_qty = 0;
    
                        if(labor_detail.length == 0){
                            msg = $filter('translate')('B0206.msg.labor_detail_empty'); //人員明細不可為空
                        } else {
                            for(var i = 0; i < labor_detail.length; i++){
                                if(labor_detail[i].labor_time == 0 && labor_detail[i].qty == 0){
                                    msg = $filter('translate')('B0206.msg.qty_and_labor_time_is_empty'); //人員產量與人時不可同時為0��?
                                    break;
                                }
                                total_labor_qty = $calculater.decimalAdd(total_labor_qty, labor_detail[i].qty);
                            }
                            if(msg == '' && parent == 'B0215'){
                                if(dialog.OutQtyOption == '3' && total_labor_qty == 0){ // 20240430 Modify by shiwl for# 0162728: [6.0.1PATCH][MSSQL/Oracle][H5][生产任务中心]作业人员工作平台，设备的数量分摊方式设为全手动输入，出站报工，提示多人产量登入数量总和不可为0
                                    msg = $filter('translate')('B0206.msg.multiple_total_qty_zero'); //多人產量登入數量總和不可��?��?
                                }
                            }
                        }
                        //判斷扣件資訊
                        if(config.cache.sys_parameter['FasteningPackage'] == 1){
                            //依照need_vehicle判斷出站是否需要維護載��?
                            if(!dialog.plotInfo.fastening_info_detail.vehicle_name
                                    || dialog.plotInfo.fastening_info_detail.vehicle_name == '' || !dialog.plotInfo.fastening_info_detail.vehicle_no){
                                if(dialog.plotInfo.fastening_info_detail.need_vehicle == 2){
                                    //無維護載具編號，請問是否繼續執行
                                    msg += $filter('translate')('B0206.msg.vehicle_info_empty');
                                } else if(dialog.plotInfo.fastening_info_detail.need_vehicle == 1){
                                    //無維護載具編號，請先維護載具資訊
                                    warring_msg += $filter('translate')('B0206.msg.vehicle_info_warning');
                                }
                            }
                            var abnormal_detail = [];
                            dialog.badReasonInfo.forEach(function (item) {
                                abnormal_detail.push({
                                    abnormal_no:item.abnormal_no,
                                    defect_qty:item.defect_qty
                                });
                            });
                            var _checkout_qty = dialog.plotInfo.qty,
                                fastening_excess_qty = 0;
                            var _temp = $filter('filter')(dialog.badReasonInfo, {abnormal_no:'FASTENINGEXCESS'}, true);
                            if(_temp && _temp.length > 0){
                                fastening_excess_qty = _temp[0].defect_qty;
                            }
                            if($calculater.decimalAdd(_checkout_qty, fastening_excess_qty) > dialog.plotInfo.fastening_info_detail.vehicle_capacity){
                                if(dialog.plotInfo.fastening_info_detail.capacity_rules == 2){
                                    //出站數量 checkout_qty 加多餘數量fastening_excess_qty，大於載具最大數��?vehicle_capacity，不允許出站��?
                                    msg += $filter('translate')('B0206.msg.vehicle_capacity_greater', {
                                        checkout_qty:_checkout_qty,
                                        fastening_excess_qty:fastening_excess_qty,
                                        vehicle_capacity:dialog.plotInfo.fastening_info_detail.vehicle_capacity});
                                } else if(dialog.plotInfo.fastening_info_detail.capacity_rules == 1){
                                    //出站數量 checkout_qty 加多餘數量fastening_excess_qty，大於載具最大數��?vehicle_capacity，是否繼續出��?
                                    warring_msg += $filter('translate')('B0206.msg.vehicle_capacity_warning',  {
                                        checkout_qty:_checkout_qty,
                                        fastening_excess_qty:fastening_excess_qty,
                                        vehicle_capacity:dialog.plotInfo.fastening_info_detail.vehicle_capacity});
                                }
                            }
                        }
                        if(msg == ''){
                            if(warring_msg == ''){
                                callback();
                            } else {
                                $rootScope.showConfirm(warring_msg, function(confirm_dialog){
                                    confirm_dialog.hide();
                                    callback();
                                });
                            }
                        } else {
                            $rootScope.showAlert(msg);
                        }
                    }
    
                    //模製具壽命檢��?
                    function SMES_AccLifeCheck(machine_no, plotInfo, callback){
                        var content = {
                            recordlist : [{
                                op_no : plotInfo.workstation_detail[0].op_no,
                                plot_no: plotInfo.workstation_detail[0].plot_no,
                                machine_no: machine_no,
                                status:'1',
                                qty : plotInfo.qty
                            }
                        ]};
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_ACC.acc_life_check_process',
                            content : content,
                            success : function(data){
                                if(data.life_manage == '0'){
                                    //警示
                                    $rootScope.showConfirm(data.description, function(confirmDialog){
                                        confirmDialog.hide();
                                        if(callback)
                                            callback();
                                    });
                                } else if(data.life_manage == '1'){
                                    //暫停生產
                                    $rootScope.showAlert(data.description);
                                } else if(data.life_manage == '2'){
                                    //核准
                                    if(callback)
                                        callback();
                                }
                            }
                        });
                    }
    
                    //生產信息收集檢查
                    function productionInfValidate(production_inf_detail){
                        var msg = '';
                        production_inf_detail.forEach(function(item){
                            if(item.productioninf_value == undefined || item.productioninf_value ==''){
                                msg +=$filter('translate')('B0206.msg.productioninf_value_empty', item)+'<br>';
                            }
                        });
                        return msg;
                    }
    
                    //取得標籤
                    function getLabel(plot_no, op_no, callback){
                        $MMWService.pageNumberInfoGet({
                            form_name: 'PageNo_71',
                            query_condition_info:[
                                {column_name:'a.OPNO', query_mode:'0', value: op_no, merge_condition_model:'AND'},
                                {column_name:'d.BASELOTNO', query_mode:'0', value: plot_no, merge_condition_model:'AND'}
                            ]
                        }, function(itemList){
                            if(callback)
                                callback(itemList);
                        });
                    }
    
                    //透過batender 打印標籤
                    function printLabel(index, commandlines){
                        if(commandlines && index < commandlines.length){
                            if(window.nodeRequire){
                                try{
                                    var exec = window.nodeRequire('child_process').exec;
                                    exec(commandlines[index], function(error, stdout, stderr){
                                        if(error){
                                            console.error(error);
                                            // $rootScope.showAlert($filter('translate')('B0206.msg.command_error', {error:error}));
                                            // 列印標籤失敗，請確認是否有正確安裝列印插件！
                                            $rootScope.showAlert($filter('translate')('B0206.msg.cantprint')); 
                                        }
                                        index = index +1;
                                        printLabel(index, commandlines);
                                    });
                                }catch(e){
                                    console.error(e);
                                    $rootScope.showAlert($filter('translate')('B0206.msg.cant_execute_bartender_command', {command:commandlines[index]}));
                                }
                            }
                        }
                    }
    
                    // PDF列印
                    function print(pdf_url, printCount){
                        // 20201110 modify by WeiTing for M#80602 - 增加多張列印功能(printCount)。
                        for(var i = 0; i < printCount; i++){
                            if(window.nodeRequire){
                                var sumatraPDF = window.nodeRequire('sumatra-pdf');
                                if(sumatraPDF){
                                    var fs = window.nodeRequire('fs'), RuncardPath;
                                    try{
                                        // 20240321 modify by Alan for#159805 : electron升級後，兼容新舊版本
                                        const remote = window.nodeRequire('electron').remote || window.nodeRequire('@electron/remote');
                                        RuncardPath = remote.app.getAppPath();
                                    }catch(e){
                                        RuncardPath = window.nodeRequire('path').dirname(process.execPath)+'\\package.nw';
                                    }
                                    RuncardPath += '\\www\\Runcard';
                                    if(!fs.existsSync(RuncardPath)){
                                        fs.mkdirSync(RuncardPath);
                                    }

                                    // 20240222 add by Alan for#158151 : 清除Runcard目錄下未開啟的舊檔案
                                    // 20240408 modify by Alan for#139948 : 改成同步讀取，避免刪除檔案後立即列印造成找不到檔案
                                    fs.readdirSync(RuncardPath, (err, files) => {
                                        if (err) {
                                            console.log(err);
                                        }
                                        //listing all files using forEach
                                        files.forEach((file) => {
                                            // Do whatever you want to do with the file
                                            fs.unlink(RuncardPath + '/' + file, (err) => {
                                                if (err) {
                                                    console.debug(err);
                                                }
                                            })
                                        });
                                    })
                
                                    // 20240222 add by Alan for#158151 : 增加時間戳記，避免檔名重複造成檔案開啟時無法寫入
                                    let pdfPath = `${RuncardPath}/RuncardPreview_${Date.now()}.pdf`;
                                    $rootScope.downloadFile(pdf_url, pdfPath, function (dist_path) {
                                        $rootScope.showLoading();
                                        // 20201110 modify by WeiTing for M#80602 - 不跳列印介面，直接使用預設列印機進行列印(printToDefault)。
                                        var _fn = sumatraPDF.printToDefault;
                                        _fn({
                                            path: dist_path,
                                            success:function(){
                                                $rootScope.hideLoading();
                                                $rootScope.showToast($filter('translate')('common.msg.success'));
                                            },
                                            error:function(error){
                                                $rootScope.hideLoading();
                                                $rootScope.showToast($filter('translate')('common.msg.success'));
                                                //console.error(error);
                                            }
                                        });
                                    });
                                } else {
                                    window.frames['kmi-pdf-panel'].pdf_print();
                                }
                            } else {
                                window.frames['kmi-pdf-panel'].pdf_print();
                            }
                        }
                    };
    
    
                    //取得取消上下工資訊
                    function equipmentBasisGet(callback) {
                        $MMWService.pageNumberInfoGet({
                            form_name: 'PageNo_60',
                            query_condition_info: [{column_name: 'EQUIPMENTNO', query_mode: '0', value: machine_no, merge_condition_model: 'AND' }]
                        }, function(itemList){
                            if(itemList.length > 0){
                                if(callback)
                                    callback(itemList[0]);
                            }
                        });
                    }
    
    
    
                    //檢查人時是否為0
                    function checkLaborDetail(data, plotData, continued) {
        
                        var temp = $filter('filter')(data.workstation_detail, function (x) { return x.labor_detail.length == 0; });
    
                        if (temp.length > 0) {
                            // 0080212: [sMES] 無法出站，出現人員尚未上工，不允許執行 [世同]
                            $rootScope.showConfirm($filter('translate')('B0206.msg.column5'), function (di) {
                                di.hide();
    
                                data.workstation_detail.forEach(e => {
                                    if (e.labor_detail.length == 0) {
                                        e.labor_detail.push({ labor_no: config.cache.account, labor_name: config.cache.name, qty: 0, _labor_time: 0, labor_time: 0 });
                                    }
                                });
    
                                dataprepare(data, plotData, continued);
                            });
                        }
                        else {
                            dataprepare(data, plotData, continued);
                        }
    
                    }
                    //20210519 Modify by德義家興for#90580
                    //取得作業站屬性plugin
                    function check_plugIn(callback){
                        var content = {
                            op_no: plot.op_no
                        };
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_MAT.check_plugIn',
                            content : content,
                            success : function(data){
                                if (callback)
                                callback(data.qty);
                            }
                        });
                    }
                    //20210519 Modify by德義家興for#90580
                    //判斷作業站屬性plugin是否=5; 5:CNC
                    function isPlugInEqualFive(){
                        check_plugIn(function(result){
                            if (parseInt(result,10) >= 1) {
                                op_plugin = true;
                            }else{
                                op_plugin = false;
                            }
                        })
                    }
                    //20210519 Modify by德義家興for#90580
                    //取得序列號收集的grid資料
                    function getPCSNoList(callback){
                        var content = {
                            op_no: plot.op_no,
                            equipment_no: machine.machine_no,
                            lot_no: plot.plot_no,
                            collection_type: "1", //0=進站, 1=出站
                        };
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.serial_num_collecting_info_get',
                            content : content,
                            success : function(data){
                                if (callback) {
                                    //20221108 modify by 翰鴻 for M#116946
                                    callback(data.serial_num_collecting_info, data.collected_PCSNo);
                                }
                            },
                            error: function(data){
                                if (callback) {
                                    callback(data.serial_num_collecting_info, data.collected_PCSNo);
                                }
                            }
                        });
                    }
                    //開窗前準備
                    function dataprepare(plotInfo, plotData, continued){
    
                        if(plotInfo.workstation_detail[0].labor_detail.length == 0){
                            $rootScope.showAlert($filter('translate')('B0206.showAlert.column7'));
                        } else {
                            //20200619 如果上次的出站數量小於可出站數量，則帶出上次出站數量，如果上次的出站數量大於等於可出站數量，則帶出可出站數量。
                            plotInfo.report_datetime = new Date();
                            //20200619 modify by Oliver localstorage.getItem()後進行運算，然後填入plotInfo.qty
                            var checkOutQty_record = JSON.parse(localStorage.getItem('checkOutQtyRecord'));
                            let lastOutputQty;
                            if(checkOutQty_record){
                                checkOutQty_record.forEach(function(item,key){
                                    if(item.lot_no === plotInfo.workstation_detail[0].plot_no && item.op_no === plotInfo.workstation_detail[0].op_no){
                                        lastOutputQty = item.record_qty;
                                        plotInfo.has_this_data = key;
                                    }
                                });
                            }
                            if(lastOutputQty && continued){
                                //0080739: [标准][DEV][生产任务中心][出站报工]出站报工画面开启载入预设数量调整
                                //20210829 Modify bychenshibo 0098995: 合达铝业出站批量设定以后无效
                                if ((+lastOutputQty) < (+plotInfo.workstation_detail[0].check_out_qty)) 
                                {
                                    plotInfo.qty = (+lastOutputQty);
                                }
                                else if ((+lastOutputQty) > (+plotInfo.workstation_detail[0].check_out_qty)) 
                                {
                                    plotInfo.qty = (+plotInfo.workstation_detail[0].check_out_qty);
                                    if ((+plotInfo.std_qty) && (+plotInfo.std_qty) > 0 && (+plotInfo.std_qty) < (+plotInfo.qty))
                                        plotInfo.qty = (+plotInfo.std_qty);
                                } else 
                                {
                                    plotInfo.qty = (+plotInfo.workstation_detail[0].check_out_qty);
                                }
                            }else{
                                plotInfo.qty = (+plotInfo.workstation_detail[0].check_out_qty);
                                if((+plotInfo.std_qty) && (+plotInfo.std_qty) > 0 && (+plotInfo.std_qty) < (+plotInfo.qty))
                                    plotInfo.qty = (+plotInfo.std_qty);
                            }
                            plotInfo.good_qty = plotInfo.qty;
                            plotInfo.workstation_detail[0].QTYACIO = CaculatQTYACIO(plotInfo.good_qty, plotInfo.workstation_detail[0].C_Numerator, plotInfo.workstation_detail[0].C_Denominator);
                            
                            //20220922 add by 翰鴻 for M#118068
                            if (IIoT_Enable) {
                                //M#91613 出站通知
                                if (plot.suggest_qty && plot.suggest_qty > 0 && plot.suggest_qty < plotInfo.qty)
                                    plotInfo.qty = plot.suggest_qty;
                            }
                            if(isNaN(plotInfo.workstation_detail[0].QTYACIO)){//增加防止出現NaN的防呆
                                plotInfo.good_qty = plotInfo.qty = (+plotInfo.workstation_detail[0].check_out_qty);
                                plotInfo.workstation_detail[0].QTYACIO = CaculatQTYACIO(plotInfo.good_qty, plotInfo.workstation_detail[0].C_Numerator, plotInfo.workstation_detail[0].C_Denominator);
                            };
    
                            //計算不良原因總數
                            plotInfo.total_abnormal_qty = 0;//報廢
                            plotInfo.total_lack_qty = 0;//短少
                            plotInfo.total_surplus_qty = 0;//多餘
                            //人員計價 總額 初始化 add by a991241234 for M# 70310
                            plotInfo.price_sum = "";
                            // 爐批號 opPlugInDetail
                            var opPlugInDetail;
                            if(!plotData.op_plug_in_detail || plotData.op_plug_in_detail.length == 0)
                                opPlugInDetail = [];
                            else
                                opPlugInDetail = plotData.op_plug_in_detail[0];
    
                            for(var i in plotInfo.workstation_detail[0].labor_detail)
                            {
                                plotInfo.workstation_detail[0].labor_detail[i].price_sum ="";
                            }
                            if(plotInfo.workstation_detail[0].abnormal_detail){
                                plotInfo.workstation_detail[0].abnormal_detail.forEach(function(abnormal_detail){
                                    if(abnormal_detail.abnormal_type == '11'){
                                        plotInfo.total_surplus_qty  = $calculater.decimalAdd((+plotInfo.total_surplus_qty), (+abnormal_detail.defect_qty));
                                    } else if(abnormal_detail.abnormal_type == '12'){
                                        plotInfo.total_lack_qty  = $calculater.decimalAdd((+plotInfo.total_lack_qty), (+abnormal_detail.defect_qty));
                                    } else {
                                        plotInfo.total_abnormal_qty = $calculater.decimalAdd((+plotInfo.total_abnormal_qty), (+abnormal_detail.defect_qty));
                                    }
                                });
                            }
                            //2018051601 modify by Dustdusk for M#45925:
                            //良品��?= 『出站數量��?- 『不良品��?- 『短少��?+ 『多餘��?
                            plotInfo.good_qty =  $calculater.decimalSub($calculater.decimalSub($calculater.decimalAdd((+plotInfo.good_qty), (+plotInfo.total_surplus_qty)), (+plotInfo.total_abnormal_qty)), (+plotInfo.total_lack_qty));
                            if(!plotInfo.workstation_detail[0].machine_qty||plotInfo.workstation_detail[0].machine_qty==''){
                                plotInfo.workstation_detail[0].machine_qty = 1;
                            }
    
                            // 20201029 modify by WeiTing for M#74130 - 作業人員工作平台(B0214)基本上是一人一機或一人多機的使用場景，所以人數修改為1人、人時取當前人員的人時。  
                            if(parent === 'B0214'){
                                if(plotInfo.workstation_detail[0].labor_detail && plotInfo.workstation_detail[0].labor_detail.length > 0){
                                    for (var i = 0; i < plotInfo.workstation_detail[0].labor_detail.length; i++){
                                        //20220801 modify by wangzy for 0116306: 东莞星河：作业人员工作平台里面个人计件人时不是单人的人时，而是变成了多人的人时之和
                                        if (config.cache.account == plotInfo.workstation_detail[0].labor_detail[i].labor_no){
                                            plotInfo.workstation_detail[0].labor_hours = plotInfo.workstation_detail[0].labor_detail[i].labor_time;
                                            break;
                                        }
                                    }
                                }
                                plotInfo.workstation_detail[0].number_of_labor = 1;
                            }
                            
                            // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                            reworkMaterialType = plotInfo.workstation_detail[0].rework_material_type;
    
                            //2018051601 modify by Dustdusk for M#45925:
                            //物料使用��?= 『良品��?+ 『不良品��?+ 『短少��?= 『出站數量��?+ 『多餘��?
                            // 20220122 modify by Alan for M#104045: 物料耗用數量計算依系統參數決定是否需計算短少或是多餘的生產數
                            var MTL_Includes_ExcessLoss = plotInfo.MTL_Includes_ExcessLoss === undefined ? true : plotInfo.MTL_Includes_ExcessLoss;
                            // 20231123 modify by wenwei for M#142054: [sMES]物料數量扣減異常[松讚]
                            // 物料使用量
                            var sum_qty = MTL_Includes_ExcessLoss
                                // 良品 + 不良 + 短少 - 多餘
                                ? (+plotInfo.good_qty) + (+plotInfo.total_abnormal_qty) + (+plotInfo.total_lack_qty) - (+plotInfo.total_surplus_qty)
                                // 良品 + 不良
                                : (+plotInfo.good_qty) + (+plotInfo.total_abnormal_qty);
                            reCalcMaterialUseQty(sum_qty);
    
                            //人員計價 出站 add by a991241234 for M# 70310
                            getPriceSum();
                            getPriceSumByLabor();
    
                            //plotInfo.workstation_detail[0].QTYACIO = plotInfo.qty *((+plotInfo.workstation_detail[0].C_Numerator)/(+plotInfo.workstation_detail[0].C_Denominator));
                            fastening_info_get(plot.plot_no, plot.op_no, function(data){
                                plotInfo.fastening_info_detail = data;
    
                                // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                                var showLogFlag = false;
                                var btnFlag = false;
                                if(reworkMethod && reworkMethod != "0" && reworkMaterialType && reworkMaterialType == "1"){
                                    showLogFlag = true;
                                }
                                if(reworkMethod && reworkMethod == "1" && reworkMaterialType && reworkMaterialType ==  "1"){
                                    btnFlag = true;
                                }
                                if (reworkMethod && reworkMethod == "2") {
                                    plotInfo.workstation_detail[0].materials_detail.forEach(item => {
                                        item.use_qty = 0;
                                    });
                                }
                                reCalcMaterialUseQty(plotInfo.qty);
                                plotInfo.continued = continued;
                                // if(reworkMethod && reworkMethod == "2"){
                                //     plotInfo.workstation_detail[0].materials_detail.forEach(item => {
                                //         item.use_qty = 0;
                                //     });
                                // }
                                //20210519 Modify by德義家興for#90580
                                openDialog(plotInfo, opPlugInDetail, showLogFlag, btnFlag, checkOutQty_record, op_plugin);
                            });
                        }
    
                    }
    
    
    
    
                    //取得載具資訊
                    function vehicle_no_info_get(vehicle_no, callback){
                        var query_condition_info = [];
                        if(vehicle_no && vehicle_no != '')
                            query_condition_info.push({column_name:'VehicleNo', query_mode:'0', value: vehicle_no, merge_condition_model:'AND'});
                        $MMWService.pageNumberInfoGet({
                            form_name: 'PageNo_120',
                            query_condition_info:query_condition_info
                        }, function(itemList){
                            if(callback)
                                callback(itemList);
                        });
                    }
    
                    //取得扣件資訊
                    function fastening_info_get(plot_no, op_no, callback){
                        if(config.cache.sys_parameter['FasteningPackage'] == '1'){
                            $MMWService.sendToServer({
                                uri: 'ServicesSTD.Module_FAS.fastening_info_get',
                                content : {
                                    plot_no:plot_no,
                                    op_no:op_no,
                                    action_type: '2' // 1(進站)、2(出站)
                                },
                                success : function(data){
                                    if(data.defaultvehicle && data.defaultvehicle!=''){
                                        vehicle_no_info_get(data.defaultvehicle, function(items){
                                            if(items && items.length > 0){
                                                data.vehicle_no = items[0].vehicle_no;
                                                data.vehicle_name = items[0].vehicle_name;
                                                data.vehicle_weight = items[0].vehicle_weight;
                                                data.vehicle_capacity = items[0].vehicle_capacity;
                                            }
                                            if(typeof(callback) == 'function'){
                                                callback(data);
                                            }
                                        });
                                    } else {
                                        if(typeof(callback) == 'function'){
                                            callback(data);
                                        }
                                    }
                                }
                            });
                        } else {
                            if(typeof(callback) == 'function'){
                                callback();
                            }
                        }
                    }
    
                    function check_checkout_qty(num, dialog, target, calcDialog){
                        if((+num) == 0 && dialog.OutQtyAllowZero == '0'){
                            $rootScope.showAlert($filter('translate')('B0206.showAlert.column1'));
                        } else if((+num)>dialog.plotInfo.workstation_detail[0].check_out_qty){
                            $rootScope.showAlert($filter('translate')('B0206.msg.column1') + num + $filter('translate')('B0206.msg.column2') + dialog.plotInfo.workstation_detail[0].check_out_qty);
                        } else{
                            dialog.plotInfo.qty = num;
                            //良品 = 出站數量 - 不良品 - 短少 + 多餘
                            dialog.plotInfo.good_qty =  $calculater.decimalSub($calculater.decimalSub($calculater.decimalAdd((+dialog.plotInfo.qty), (+dialog.plotInfo.total_surplus_qty)), (+dialog.plotInfo.total_abnormal_qty)), (+dialog.plotInfo.total_lack_qty));
                                //2018051601 modify by Dustdusk for M#45925:
                                //物料使用��?= 『良品��?+ 『不良品��?+ 『短少��?= 『出站數量��?+ 『多餘��?
                                // 20220122 modify by Alan for M#104045: 物料耗用數量計算依系統參數決定是否需計算短少或是多餘的生產數
                                var MTL_Includes_ExcessLoss = dialog.plotInfo.MTL_Includes_ExcessLoss === undefined ? true : dialog.plotInfo.MTL_Includes_ExcessLoss;
                                // 20231123 modify by wenwei for M#142054: [sMES]物料數量扣減異常[松讚]
                                // 物料使用量
                                var sum_qty = MTL_Includes_ExcessLoss
                                    // 良品 + 不良 + 短少 - 多餘
                                    ? (+plotInfo.good_qty) + (+plotInfo.total_abnormal_qty) + (+plotInfo.total_lack_qty) - (+plotInfo.total_surplus_qty)
                                    // 良品 + 不良
                                    : (+plotInfo.good_qty) + (+plotInfo.total_abnormal_qty);
                                reCalcMaterialUseQty(sum_qty);
                                //2018051601 modify by Dustdusk for M#45925:
                                //如果良品��?= 『出站數量��?- 『不良品��?- 『短少��?+ 『多餘��?小於0則清空例外原��?
                                if(((+num) + dialog.plotInfo.total_surplus_qty) < ((+dialog.plotInfo.total_abnormal_qty)+(+dialog.plotInfo.total_lack_qty))){
                                    calcDialog.hide();
                                    var total_abnormal_qty = dialog.plotInfo.total_abnormal_qty;
                                    var total_surplus_qty = dialog.plotInfo.total_surplus_qty;
                                    var total_lack_qty = dialog.plotInfo.total_lack_qty;
                                    dialog.plotInfo.total_abnormal_qty = 0;
                                    dialog.plotInfo.total_surplus_qty = 0;
                                    dialog.plotInfo.total_lack_qty = 0;
                                    dialog.badReasonInfo = [];
                                    dialog.plotInfo.good_qty = num;
                                    dialog.plotInfo.workstation_detail[0].QTYACIO = CaculatQTYACIO(dialog.plotInfo.good_qty, dialog.plotInfo.workstation_detail[0].C_Numerator, dialog.plotInfo.workstation_detail[0].C_Denominator);
                                    $rootScope.showAlert($filter('translate')('B0206.msg.qty_less_than_abnormal_qty', {abnormal_qty:(total_abnormal_qty+total_lack_qty-total_surplus_qty)}), function(){
                                        //多人產量登入
                                        reCalcMultipleQty(dialog, function(){});
                                    });
                                } else {
                                    //2018051601 modify by Dustdusk for M#45925:
                                    //良品��?= 『出站數量��?- 『不良品��?- 『短少��?+ 『多餘��?
    
                                    //20211029 modify by 翰鴻 for Mantis#97211:
                                    //出站後生產批數量 = 生產批現況數量 - 良品 - 不良品 
                                    //良品 = 輸入量
                                    var lastqty;
                                    var content = {
                                        machine_no: machine_no,
                                        plot_no: plot.plot_no,
                                        op_seq: '',//
                                        op_no: plot.op_no,
                                        workstation_no: '',//
                                        qty: '',
                                        return_type: '2',
                                        op_plug_in: plot.op_plug_in
                                    };
                                    if (parent == 'B0214') {
                                        content.mode = '1';
                                    }
    
                                    lastqty = plotInfo.workstation_detail[0].CheckOutPlotQty;
                                    dialog.leftqty = $calculater.decimalSub(
                                                (+lastqty),
                                                $calculater.decimalAdd((+num), (+dialog.plotInfo.total_abnormal_qty))
                                            );
                                    dialog.plotInfo.good_qty =  $calculater.decimalSub($calculater.decimalSub($calculater.decimalAdd((+num), (+dialog.plotInfo.total_surplus_qty)), (+dialog.plotInfo.total_abnormal_qty)), (+dialog.plotInfo.total_lack_qty));
                                    // 20230321 modify by 文蔚 M#130627: 出站報工介面數量為負數
                                    if (dialog.leftqty < 0 && ($calculater.decimalAdd((+dialog.plotInfo.total_surplus_qty), (+dialog.plotInfo.total_lack_qty)) > 0)) dialog.leftqty = 0
                                    //20220525 modify by wangzy M#0112778: 單位轉換後TBLWIPCONT_RESOURCE數量不準確
                                    dialog.plotInfo.workstation_detail[0].QTYACIO = CaculatQTYACIO((+num), dialog.plotInfo.workstation_detail[0].C_Numerator, dialog.plotInfo.workstation_detail[0].C_Denominator);
                                    calcDialog.hide();
                                    //多人產量登入
                                    reCalcMultipleQty(dialog, function(){});
                                }
                            angular.element(target).removeClass('is-focus');
                        }
                    }
    
                    //開窗
    
                    //20210519 Modify by德義家興for#90580
                    var openDialog = function (plotInfo, opPlugInDetail, showLogFlag, btnFlag, checkOutQty_record, op_plugin) {
                        //20211029 modify by 翰鴻 for Mantis#97211:
                        var leftqty = 
                            $calculater.decimalSub(
                                                (+plotInfo.workstation_detail[0].CheckOutPlotQty),
                                                $calculater.decimalAdd((+plotInfo.qty), (+plotInfo.total_abnormal_qty))
                                                );
                      
                        plotInfo.wait_reason_detail = [];
                        $mddProvider.UseForm('B0206', () => {
                                $mdDialog.dialog(
                                        'module/moduleB/program/B02/B0206/B0206.html',
                                        function(dialog){
                                            dialog.op_plug_in = plot.op_plug_in
                                            return {
                                                leftqty: leftqty,
                                                css_url:'module/moduleB/program/B02/B0206/B0206.css',
                                                isRequire:plotInfo.production_inf_type=='2',
                                                plotInfo:plotInfo,
                                                checkOutQty_record:checkOutQty_record || [],
                                                mode : mode,
                                                title:plotInfo.continued  == true ? $filter('translate')('B0206.title_continued') : $filter('translate')('B0206.title'),
                                                badCodeList:badCodeList,
                                                tmpBadReason : tmpBadReason,
                                                tmpAbnormal_qty: tmpAbnormal_qty,
                                                badReasonInfo:plotInfo.workstation_detail[0].abnormal_detail,
                                                parent:parent,
                                                scan_func_val:'',
                                                 open_scan_column : plot.open_scan_column,
                                                backToTrackOut:backToTrackOut,//返回出站報工畫面
                                                tmpLabor_no: '',
                                                OutQtyDefinition: '0', // 出站數量認定 0:良品��?1:良品數＋不良��?(尚未使用)
                                                OutQtyAllowZero: '0', // 出站量可為零 0: 不允��?1: 允許
                                                OutQtyOption: '0', // 數量分攤方式 0:原邏��?1: 均分 2: 按在線時間分��?3:全手動輸��?
                                                IsInjectionMolding: config.cache.sys_parameter['IsInjectionMolding'], // 20200225 modify by WeiTing for M#67404: 注塑模組 - 0: 不顯示 ; 1: 顯示注塑模組。
                                                op_plug_in: plot.op_plug_in, // 是否有爐批號 → 0(無) ; 1(有)
                                                heat_plot_no: opPlugInDetail.heat_plot_no || '', // 爐批號
                                                // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                                                reworkFlag: showLogFlag,
                                                logFlag: false,
                                                showBtnFlag: btnFlag,                        
                                                lastItem: '',
                                                FasteningPackage: config.cache.sys_parameter.FasteningPackage, // 紧固件行业包 → 0(關閉) ; 1(開啟)
                                                //20210519 Modify by德義家興for#90580
                                                isPlugInEqualFive: op_plugin, //序列號收集按鈕是否顯示
                                                PCSNo: '', //用來判斷目前是選到哪個產品序列號;例外原因需與個別產品序列號連結
                                                PCSNoList:[], //序列號收集grid
                                                PCSNoList_count: 0, //grid的筆數
                                                PCSNoList:[],
                                                PCSNoBadReasonList: [],
                                                PCSNoHasBadReason: undefined, //true:在序列號收集裡設定不良原因,false:出站畫面設定不良原因,undefined:都沒設定
                                                _event: {
                                                    'dialog.B0206_MutripleOp_laborDetail.qty': {  //  20231128 modify by shiwl for M# 0151544: MES6.0,多人产量登录，小键盘带不出小数点
                                                        click: (qty,{eventScope,event}) => {
                                                           dialog.laborInputQty(event,eventScope);
                                                         }      
                                                    },
                                                   'vehicle_no': {
                                                     click: () => {
                                                        dialog.loadVehicleList();
                                                      }      
                                                    }, // 刷入序号
                                                   'B0206_ExceptionReason_tmpBadTypeName': {                                                              
                                                      change:(value, {event})=>{
                                                          dialog.bd_scan(event);
                                                       },
                                                      click:()=>{
                                                         dialog.qrcode_plot_no();
                                                       }                                                              
                                                    }, // 多人产量登入
                                                    'B0206_MutripleOp_tmpLabor_no':{
                                                        change:(value, {event})=>{ 
                                                           dialog.searchLabor(event);
                                                         },
                                                         click:()=>{
                                                                dialog.searchLabor();
                                                         }
                                                    },// 序列号收集 - 产品序列号输入  
                                                    'B0206_Serial_Number_Collecte_tmpPCSNo':{
                                                        change:(value, {event})=>{ 
                                                           dialog.enter_PCSNo(event);
                                                         },
                                                         click:()=>{
                                                                dialog.qrcode_PCSNo();
                                                         }
                                                    }, //序列号收集 - 确定 
                                                    'B0206_Sub_product_Execute':{
                                                        change:(value, {event})=>{ 
                                                           dialog.enter_PCSNo(event);
                                                         },
                                                         click:()=>{
                                                                dialog.PCSNoConfirm();
                                                         }
                                                    }, // B0206_vehicle_no
                                                    'B0206_vehicle_no':{
                                                        change:(value, {event})=>{ 
                                                                dialog.keyVehicleList(event);
                                                         },
                                                         click:()=>{
                                                                dialog.loadVehicleList();
                                                         }
                                                    },
                                                    // 20230222 modify by Alan for M#128539: 補上機時數字鍵盤
                                                    'B0206_machine_hours': {
                                                        click: (machine_hours, args) => dialog.machine_hours_qty(args.event)
                                                    },
                                                    'B0206_heat_plot_no':{
                                                        isShown: (dialog.op_plug_in == '1') ? 'Y':'N'
                                                    },
                                                    // 20230223 modify by 文蔚 for M#128731: 使返回按鈕可以回到上一頁，而非第一頁
                                                    // 20230222 modify by Alan for M#128535: 修正換頁卡控
                                                    'PageChange' :(formEntity) =>{ 
                                                        if (dialog._nowForm == 'B0206_Collected_PCSNo') {
                                                            dialog.changeForm('B0206_Serial_Number_Collecte');
                                                            backToTrackOut(dialog);
                                                            dialog.mode = 'PCSNo';
                                                        } else if(dialog._nowForm == 'B0206_ExceptionReasonForSerialNo')  {
                                                            dialog.changeForm('B0206_Serial_Number_Collecte');
                                                            backToTrackOut(dialog);
                                                        } else {
                                                            dialog._nowForm = formEntity.name;
                                                            dialog._title = formEntity.displayText;
                                                        }
                                                    },
                                                    'qty':{
                                                        isShown: dialog.FasteningPackage =='1' || dialog.FasteningPackage == 'Y'
                                                    }
                                                },
                                                _fn: {
                                                  // 序列号收集跳转到已收集序列号
                                                  // 20230324 modify by 文蔚 for M#130733 使返回按鈕可以回到上一頁 補設定
                                                'B0206_Serial_Number_Collecte_opem_Collected':{
                                                    click: () => {
                                                        dialog.mode = 'collectedPCSNo';
                                                        dialog.changeForm('B0206_Collected_PCSNo');
                                                    }   
                                                },
                                                 'B0206_B0206_Serial_Number_Collecte':{
                                                    isShown: ('B0214'=='B0214')?'Y':'N'
                                                 },   
                                                  // 已收集序列号
                                                 'B0206_B0206_Collected_PCSNo':{
                                                        isShown: ('B0214'=='B0214')?'Y':'N'
                                                 },
                                                 'B0206_production_inf_detail':{ //開啟生產信息收集
                                                         click:()=>{
                                                             dialog.productionInf_open();
                                                         }
                                                     },
                                                   'dialog.B0206_B0206_production_inf_detail':{
                                                          isShown:'N'
                                                      },
                                                   
                                                  'Execute': {  // 出站
                                                     click: () => {
                                                       dialog.checkReworkType(2,dialog);
                                                        
                                                     }                                                                                                                          
                                                  },
                                                   'B0206_Execute': {  // 持续出站
                                                      click: () => {
                                                         dialog.checkReworkType(1,dialog);
                                                      }                                                                  
                                                   },
                                                  'B0206_ExceptionReason_B0206_ExceptionReason_ConfirmButton':{ //開啟不良原因
                                                     click:()=>{
                                                         dialog.badReasonConfirm();
                                                     }
                                                  },
                                                  'B0206_MutripleOp_MultipleConfirm_Execute':{ // 多人产量登入修改列表
                                                        click:()=>{
                                                                dialog.multipleConfirm();
                                                        }
                                                     },
                                                     
                                                  'B0206_production_inf_detail_Execute':{ // 多人产量登入修改列表
                                                     click:()=>{
                                                             dialog.productionInfConfirm();
                                                     }
                                                  }, 
                                                  'B0206_Sub_product_Execute':{ // 副产品确认
                                                        click:()=>{
                                                                dialog.subProductConfirm();
                                                        }
                                                   },
                                                   'B0206_B0206_Sub_product':{
                                                       isShown: 'Y'
                                                   },
                                                   'B0206_Serial_Number_Collecte_Execute':{
                                                        change:(value, {event})=>{ 
                                                           dialog.enter_PCSNo(event);
                                                         },
                                                         click:()=>{
                                                                dialog.PCSNoConfirm();
                                                         }
                                                    },
                                                    // 20230303 modify by Alan for M#128535: 補上缺少功能
                                                    'dialog.B0206_Serial_Number_Collecte_PCSNoList.badReason': {
                                                        click: (badReason, name, args) => dialog.check_original_bad_page(args.eventScope)
                                                    },
                                                    'B0206_ExceptionReasonForSerialNo_B0206_ExceptionReason_ConfirmButton': {
                                                        click: () => dialog.badReasonConfirm()
                                                    },
                                                },
                                                init:function(){  
                                                  dialog.showFasteningPackage();                                         
                                                },
                                                beforeShown: function () {
                                                    equipmentBasisGet(function (data) {
                                                        dialog.OutQtyDefinition = data.outqtydefinition || '0';
                                                        dialog.OutQtyAllowZero = data.outqtyallowzero || '0';
                                                        dialog.OutQtyOption = data.outqtyoption || '0';
                                                        //多人產量登入
                                                        multipleRecalculateImp(dialog, function(){});
                                                    });
                                                    /*
                                                    20200114 modify by Dustdusk for M#: 暫時關閉此功��?
                                                    if(parent != 'B0201'){
                                                        //取得標籤資料
                                                        getLabel(plot.plot_no, plot.op_no, function(itemList){
                                                            _labelInfo = itemList;
                                                            if(_labelInfo && _labelInfo.length > 0){
                                                                dialog.plotInfo.label_no = _labelInfo[0].label_no;
                                                            } else {
                                                                dialog.plotInfo.label_no = '';
                                                            }
                                                        });
                                                    }
                                                    */
                                                    document.querySelector("#tmpBadTypeName").focus();//將焦點移回刷不良原因的條碼欄位。

                                                },
                                                paramtershow: function () {
                                                    if (config.cache.sys_parameter['UCBModule'] == '1')
                                                    {
                                                        return true;
                                                    }
                                                    else
                                                        return false;
                                                },
                                                showRuleYield: function(){
                                                    return dialog.plotInfo.rule_yield_ls != '' || dialog.plotInfo.rule_yield_lcl !='';
                                                },
                                                showLabel:function(){
                                                    if(parent != 'B0201' && _labelInfo && _labelInfo.length > 0){
                                                        return true;
                                                    } else {
                                                        return false;
                                                    }
                                                },
                                                trackOutLabel: function(){
                                                    $rootScope.showQueryList({
                                                        key:'page_no',
                                                        selectCode:dialog.plotInfo.label_no,
                                                        beforeShown:function(){
                                                        },
                                                        query: function(conditions, feedback){
                                                            feedback(_labelInfo);
                                                        },
                                                        header: [
                                                            {label: $filter('translate')('B0206.trackOut.label_type'), code:'label_type'},
                                                            {label: $filter('translate')('B0206.trackOut.label_no'), code:'label_no'}
                                                        ],
                                                        confirm : function(selectItem){
                                                            dialog.plotInfo.label_no = selectItem.label_no;
                                                        },
                                                        cancel : function(query_dialog){
                                                            query_dialog.hide();
                                                            dialog.plotInfo.label_no = '';
                                                        }
                                                    });
                                                },
                                                func_scan:function(event){
                                                    if(event.keyCode == 13){
                                                        if(dialog.scan_func_val==='ORD_000_A006'){//例外狀態
                                                            dialog.openBadPage();
                                                        }else if(dialog.scan_func_val==='ORD_000_A007'){//多人生產
                                                            if(dialog.parent == 'B0214'){
                                                                $rootScope.showAlert($filter('translate')('B0206.showAlert.column10'));
                                                            }else{
                                                                dialog.openMultiplePage();
                                                                $timeout(function(){
                                                                    document.querySelector(".value.searching-client").focus();
                                                                });
                                                            }
                                                        }else if(dialog.scan_func_val==='ORD_000_A010'){//持續出站
                                                            dialog.trackOutConfirmContinued();
                                                        }else if(dialog.scan_func_val==='ORD_000_A008'){//確認
                                                            dialog.trackOutConfirm();
                                                        }else if(dialog.scan_func_val==='ORD_000_A009'){//關閉
                                                            dialog.trackOutBack();
                                                        }else{
                                                            $rootScope.showAlert($filter('translate')('B0205.showAlert.column4'));
                                                        }
                                                        dialog.scan_func_val='';
                                                    }
                                                },
                                                //QRCode輸入
                                                qrcode_plot_no : function(){
                                                    $rootScope.OpenScanner({
                                                        after : function(result){
                                                            input_plot_no_callback(result.text);
                                                        },
                                                        exception: function(){
                                                            //目前裝置無法使用相機
                                                            $rootScope.showAlert($filter('translate')('B0214.showAlert.column3'));
                                                        },
                                                        orientation : 'landscape'
                                                    });
                                                },
                                                labor_hours_qty:function(event){//修改人時數字
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,hrCalcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        dialog.plotInfo.workstation_detail[0].labor_hours = (+num);
                                                        document.querySelector("#tmpBadTypeName").focus();
                                                        //將焦點移回刷不良原因的條碼欄位。
                                                        hrCalcDialog.hide();
                                                    },
                                                    function(hrCalcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        hrCalcDialog.hide();
                                                    },
                                                    {
                                                        defaultNum : dialog.plotInfo.workstation_detail[0].labor_hours,
                                                        decimal : true
                                                    });
                                                },
                                                machine_hours_qty:function(event){//修改機時數字
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,maCalcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        dialog.plotInfo.workstation_detail[0].machine_hours = (+num);
                                                        document.querySelector("#tmpBadTypeName").focus();//將焦點移回刷不良原因的條碼欄位。

                                                        maCalcDialog.hide();
                                                    },
                                                    function(maCalcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        maCalcDialog.hide();
                                                    },
                                                    {
                                                        defaultNum : dialog.plotInfo.workstation_detail[0].machine_hours,
                                                        decimal : true
                                                    });
                                                },
                                                trackOutInputQty: function(event, trackOutQty){
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,calcDialog){
                                                        if((+num)!=trackOutQty){
                                                            check_checkout_qty(num, dialog, target, calcDialog);
                                                        }else{
                                                            calcDialog.hide();
                                                        }
                                                        getPriceSum(); getPriceSumByLabor();
                                                        document.querySelector("#tmpBadTypeName").focus();//將焦點移回刷不良原因的條碼欄位。

                                                    },
                                                    function(calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        calcDialog.hide();
                                                    },
                                                    {
                                                            defaultNum : trackOutQty,
                                                            decimal : true
                                                    });
                                                },
                                                trackPeopleTime:function(event, trackTime)
                                                {
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        calcDialog.hide();
                                                        dialog.plotInfo.workstation_detail[0].labor_hours = num;
                                                        getPriceSum();
                                                        getPriceSumByLabor();
                                                    },
                                                    function(calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        calcDialog.hide();
                                                    },
                                                    {
                                                            defaultNum : trackTime,
                                                            decimal : true
                                                    });
                                                },
                                                //20191130 modify by Dustdusk for M#62692: 增加顯示扣件行業相關欄位
                                                showFasteningPackage: function(){
                                                        if(config.cache.sys_parameter['FasteningPackage']=='1'){
                                                           dialog._event['B0206_vehicle_no'].isShown = 'Y';
                                                           dialog._event['qty'].isShown = 'Y';
                                                        }else{
                                                           dialog._event['B0206_vehicle_no'].isShown = 'N'; 
                                                           dialog._event['qty'].isShown = 'N'; 
                                                        }
                                                       
                                                      //  dialog._event['B0206_price_type_name'].isShown = 'N';
                                                  //  return config.cache.sys_parameter['FasteningPackage']==1;
                                                },
                                                trackOutVehicleQty:function(event, VehicleQty){ // 雙單位計算出站數量
                                                    //依照need_vehicle判斷出站是否需要維護載��?
                                                    if(!dialog.plotInfo.fastening_info_detail.vehicle_name
                                                            || dialog.plotInfo.fastening_info_detail.vehicle_name == ''){
                                                        if(dialog.plotInfo.fastening_info_detail.need_vehicle == 2){
                                                            //無維護載具編號，請問是否繼續執行
                                                            $rootScope.showAlert($filter('translate')('B0206.msg.vehicle_info_empty'));
                                                            return;
                                                        }
                                                    }
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    if(dialog.plotInfo.fastening_info_detail.molecule > 0 && dialog.plotInfo.fastening_info_detail.denominator > 0){
                                                        $calculater.open(function(num,calcDialog){
                                                            angular.element(target).removeClass('is-focus');
                                                            if(+num <= 0){
                                                                // 雙單位數量不能小於等於0
                                                                $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column6'));
                                                            } else {
                                                                var _checkout_qty = dialog.trackOutVehicleQtyCallback(+num);
                                                                if(_checkout_qty > 0){
                                                                    if(_checkout_qty > dialog.plotInfo.workstation_detail[0].check_out_qty){
                                                                        // 轉換數量 + _checkout_qty + 超出出站數量 + dialog.plotInfo.workstation_detail[0].check_out_qty +，轉換失敗，請重新輸入
                                                                        return $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column1') + _checkout_qty 
                                                                            + $filter('translate')('B0206.vehicleMsg.column4') + dialog.plotInfo.workstation_detail[0].check_out_qty
                                                                            + $filter('translate')('B0206.vehicleMsg.column7'));
                                                                    } else {
                                                                        dialog.plotInfo.fastening_info_detail.double_unit_qty = (+num);
                                                                        dialog.plotInfo.fastening_info_detail.vehicle_qty = _checkout_qty;
                                                                        check_checkout_qty(_checkout_qty, dialog, target, calcDialog);
                                                                    }
                                                                } else {
                                                                    // 轉換數量 + _checkout_qty + 小於等於0，轉換失敗，請重新輸入
                                                                    return $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column1') + _checkout_qty 
                                                                        + $filter('translate')('B0206.vehicleMsg.column2') + $filter('translate')('B0206.vehicleMsg.column7'));
                                                                }
                                                            }
                                                        },
                                                        function(calcDialog){
                                                            angular.element(target).removeClass('is-focus');
                                                            calcDialog.hide();
                                                        },
                                                        {
                                                            defaultNum : VehicleQty,
                                                            decimal : true
                                                        });
                                                    } else {
                                                        // 雙單位轉換率分子或分母不得為0
                                                        $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column3'));
                                                    }
                                                },
                                                changeMoleculeValue: function(event){ // 更換雙單位轉換率分子
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        var originMoleculeValue = dialog.plotInfo.fastening_info_detail.molecule; // 先保留原本的轉換率分子
                                                        if(dialog.plotInfo.fastening_info_detail.double_unit_qty){
                                                            if(+num == 0){
                                                                // 已經輸入雙單位數量，不能變更為0
                                                                return $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column5'));
                                                            } else {
                                                                dialog.plotInfo.fastening_info_detail.molecule = (+num); // 先更換轉換率分子進行計算，轉換失敗會在還原
                                                                var _checkout_qty = dialog.trackOutVehicleQtyCallback(+dialog.plotInfo.fastening_info_detail.double_unit_qty);
                                                                if(_checkout_qty > 0){
                                                                    if(_checkout_qty > dialog.plotInfo.workstation_detail[0].check_out_qty){
                                                                        dialog.plotInfo.fastening_info_detail.molecule = originMoleculeValue; // 轉換失敗，需還原原本的轉換率分子
                                                                        // 轉換數量 + _checkout_qty + 超出可出站數量 + dialog.plotInfo.workstation_detail[0].check_out_qty +，轉換失敗，請重新輸入
                                                                        return $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column1') + _checkout_qty 
                                                                            + $filter('translate')('B0206.vehicleMsg.column4') + dialog.plotInfo.workstation_detail[0].check_out_qty
                                                                            + $filter('translate')('B0206.vehicleMsg.column7'));
                                                                    } else {
                                                                        dialog.plotInfo.fastening_info_detail.molecule = (+num);
                                                                        dialog.plotInfo.fastening_info_detail.vehicle_qty = _checkout_qty;
                                                                        check_checkout_qty(_checkout_qty, dialog, target, calcDialog);
                                                                    }
                                                                } else {
                                                                    // 轉換數量 + _checkout_qty + 小於等於0，轉換失敗，請重新輸入
                                                                    return $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column1') + _checkout_qty 
                                                                        + $filter('translate')('B0206.vehicleMsg.column2') + $filter('translate')('B0206.vehicleMsg.column7'));
                                                                }
                                                            }
                                                        } else {
                                                            dialog.plotInfo.fastening_info_detail.molecule = (+num);
                                                            calcDialog.hide();
                                                        }
                                                    },
                                                    function(calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        calcDialog.hide();
                                                    },
                                                    {
                                                        defaultNum : dialog.plotInfo.fastening_info_detail.molecule,
                                                        decimal : true
                                                    });
                                                },
                                                changeDenominatorValue: function(event){ // 更換雙單位轉換率分母
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        var originDenominatorValue = dialog.plotInfo.fastening_info_detail.denominator; // 先保留原本的轉換率分母
                                                        if(dialog.plotInfo.fastening_info_detail.double_unit_qty){
                                                            if(+num == 0){
                                                                // 已經輸入雙單位數量，不能變更為0
                                                                return $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column5'));
                                                            } else {
                                                                dialog.plotInfo.fastening_info_detail.denominator = (+num); // 先更換轉換率分母進行計算，轉換失敗會在還原
                                                                var _checkout_qty = dialog.trackOutVehicleQtyCallback(+dialog.plotInfo.fastening_info_detail.double_unit_qty);
                                                                if(_checkout_qty > 0){
                                                                    if(_checkout_qty > dialog.plotInfo.workstation_detail[0].check_out_qty){
                                                                        dialog.plotInfo.fastening_info_detail.denominator = originDenominatorValue; // 轉換失敗，需還原原本的轉換率分子
                                                                        // 轉換數量 + _checkout_qty + 超出可出站數量 + dialog.plotInfo.workstation_detail[0].check_out_qty +，轉換失敗，請重新輸入
                                                                        return $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column1') + _checkout_qty 
                                                                            + $filter('translate')('B0206.vehicleMsg.column4') + dialog.plotInfo.workstation_detail[0].check_out_qty
                                                                            + $filter('translate')('B0206.vehicleMsg.column7'));
                                                                    } else {
                                                                        dialog.plotInfo.fastening_info_detail.denominator = (+num);
                                                                        dialog.plotInfo.fastening_info_detail.vehicle_qty = _checkout_qty;
                                                                        check_checkout_qty(_checkout_qty, dialog, target, calcDialog);
                                                                    }
                                                                } else {
                                                                    // 轉換數量 + _checkout_qty + 小於等於0，轉換失敗，請重新輸入
                                                                    return $rootScope.showAlert($filter('translate')('B0206.vehicleMsg.column1') + _checkout_qty 
                                                                        + $filter('translate')('B0206.vehicleMsg.column2') + $filter('translate')('B0206.vehicleMsg.column7'));
                                                                }
                                                            } 
                                                        } else {
                                                            dialog.plotInfo.fastening_info_detail.denominator = (+num);
                                                            calcDialog.hide();
                                                        }
                                                    },
                                                    function(calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        calcDialog.hide();
                                                    },
                                                    {
                                                        defaultNum : dialog.plotInfo.fastening_info_detail.denominator,
                                                        decimal : true
                                                    });
                                                },
                                                trackOutVehicleQtyCallback: function(num){ // 雙單位計算出站數量callback
                                                    var _checkout_qty = CaculateFastening(dialog.plotInfo.fastening_info_detail, (+num));
                                                    if(+_checkout_qty > +dialog.plotInfo.workstation_detail[0].check_out_qty){
                                                        if(dialog.plotInfo.fastening_info_detail.double_unit_rules == 2){
                                                            $rootScope.showAlert($filter('translate')('B0206.msg.column1') + _checkout_qty + $filter('translate')('B0206.msg.column2') + dialog.plotInfo.workstation_detail[0].check_out_qty);
                                                            return +_checkout_qty || 0;//添加数量返回提供给显示
                                                        } else if(dialog.plotInfo.fastening_info_detail.double_unit_rules == 1){
                                                            var _temp = $filter('filter')(dialog.badReasonInfo, {abnormal_no:'FASTENINGEXCESS'}, true);
                                                            var _fastening_excess_qty = $calculater.decimalSub(_checkout_qty, dialog.plotInfo.workstation_detail[0].check_out_qty);
                                                            if(_temp && _temp.length > 0){
                                                                dialog.plotInfo.total_surplus_qty = $calculater.decimalAdd($calculater.decimalSub(dialog.plotInfo.total_surplus_qty, _temp[0].defect_qty), _fastening_excess_qty);
                                                                _temp[0].defect_qty = _fastening_excess_qty;
                                                            } else {
                                                                dialog.badReasonInfo.push({
                                                                    plot_no: dialog.plotInfo.workstation_detail[0].plot_no,
                                                                    abnormal_type : '11',
                                                                    abnormal_type_name : $filter('translate')('B0206.badReason.surplus_type'),
                                                                    abnormal_no : 'FASTENINGEXCESS',
                                                                    abnormal_name : $filter('translate')('B0206.badReason.fastening_excess'),
                                                                    defect_qty: _fastening_excess_qty,
                                                                });
                                                                dialog.plotInfo.total_surplus_qty = $calculater.decimalAdd(dialog.plotInfo.total_surplus_qty, _fastening_excess_qty);
                                                            }
                                                        }
                                                        _checkout_qty = +dialog.plotInfo.workstation_detail[0].check_out_qty;
                                                    } else {
                                                        var _temp = $filter('filter')(dialog.badReasonInfo, {abnormal_no:'FASTENINGEXCESS'}, true);
                                                        for(var i = 0; i < dialog.badReasonInfo.length;i++){
                                                            if(dialog.badReasonInfo[i].abnormal_no == 'FASTENINGEXCESS'){
                                                                dialog.plotInfo.total_surplus_qty = $calculater.decimalAdd(dialog.plotInfo.total_surplus_qty, dialog.badReasonInfo[i].defect_qty);
                                                                dialog.badReasonInfo.splice(i, 1);
                                                                break;
                                                            }
                                                        };
                                                    }
                                                    return +_checkout_qty || 0;
                                                },
                                                keyVehicleList:function(event){
                                                    if(event.keyCode == 13){
                                                        if(dialog.plotInfo.fastening_info_detail.vehicle_no && dialog.plotInfo.fastening_info_detail.vehicle_no != ''){
                                                            vehicle_no_info_get(dialog.plotInfo.fastening_info_detail.vehicle_no, function(items){
                                                                if(items && items.length > 0){
                                                                    dialog.plotInfo.fastening_info_detail.vehicle_no = items[0].vehicle_no;
                                                                    dialog.plotInfo.fastening_info_detail.vehicle_name = items[0].vehicle_name;
                                                                    dialog.plotInfo.fastening_info_detail.vehicle_weight = items[0].vehicle_weight;
                                                                    dialog.plotInfo.fastening_info_detail.vehicle_capacity = items[0].vehicle_capacity;
                                                                    dialog.plotInfo.fastening_info_detail.double_unit_qty = undefined; // 有載具編號的情況，雙單位計算公式會不同，所以刷新載具編號時，也要重新輸入雙單位數量
                                                                } else {
                                                                    $rootScope.showAlert($filter('translate')('common.msg.no_data'));
                                                                    dialog.plotInfo.fastening_info_detail.vehicle_no = '';
                                                                    dialog.plotInfo.fastening_info_detail.vehicle_name = '';
                                                                    dialog.plotInfo.fastening_info_detail.vehicle_weight = '';
                                                                    dialog.plotInfo.fastening_info_detail.vehicle_capacity = '';
                                                                }
                                                            });
                                                        } else {
                
                                                            dialog.plotInfo.fastening_info_detail.vehicle_no = '';
                                                            dialog.plotInfo.fastening_info_detail.vehicle_name = '';
                                                            dialog.plotInfo.fastening_info_detail.vehicle_weight = '';
                                                            dialog.plotInfo.fastening_info_detail.vehicle_capacity = '';
                                                        }
                                                    }
                                                },
                                                loadVehicleList:function(){
                                                    $rootScope.showQueryList({
                                                        header: [
                                                            {label:$filter('translate')('B0206.trackOut.vehicle_no'), code:'vehicle_no'},
                                                            {label:$filter('translate')('B0206.trackOut.vehicle_name'), code:'vehicle_name'},
                                                            {label:$filter('translate')('B0206.trackOut.vehicle_weight'), code:'vehicle_weight'},
                                                            {label:$filter('translate')('B0206.trackOut.vehicle_capacity'), code:'vehicle_capacity'}
                                                        ],
                                                        query: function(conditions, feedback){
                                                            vehicle_no_info_get('', feedback);
                                                        },
                                                        selectCode:dialog.plotInfo.fastening_info_detail.vehicle_no,
                                                        confirm : function(selectItem, query_dialog){
                                                            dialog.plotInfo.fastening_info_detail.vehicle_no = selectItem.vehicle_no;
                                                            dialog.plotInfo.fastening_info_detail.vehicle_name = selectItem.vehicle_name;
                                                            dialog.plotInfo.fastening_info_detail.vehicle_weight = selectItem.vehicle_weight;
                                                            dialog.plotInfo.fastening_info_detail.vehicle_capacity = selectItem.vehicle_capacity;
                                                            dialog.plotInfo.fastening_info_detail.double_unit_qty = undefined; // 有載具編號的情況，雙單位計算公式會不同，所以刷新載具編號時，也要重新輸入雙單位數量
                                                            query_dialog.hide();
                                                        }
                                                    });
                                                },
                                                trackOutBack: function () {
                                                    //20210519 Modify by德義家興for#90580
                                                    if (dialog.mode == 'PCSNo') {
                                                        if (dialog.PCSNoList_count >= 1) {
                                                            dialog.update_PlotInfo_Qty();
                                                        }
                                                        dialog.mode = 'trackOut';
                                                    }else if (dialog.mode == 'newBadReason') {
                                                        dialog.mode = 'PCSNo';
                                                        // 20230303 modify by Alan for M#128535: 補上缺少功能
                                                        dialog.changeForm('B0206_Serial_Number_Collecte');
                                                    }else{
                                                        dialog.hide();
                                                    }
                                                    //focus()
                                                },
                                                //出站確認
                                                trackOutConfirm: function(){
                                                    if(dialog.isRequire){
                                                        $rootScope.showAlert($filter('translate')('B0206.msg.production_inf_require'), function(){
                                                            dialog.openProductionInfPage();
                                                        });
                                                    } else if(dialog.plotInfo.good_qty < 0) {
                                                        $rootScope.showAlert($filter('translate')('B0206.msg.good_qty_less_than_zero'));
                                                    } else if(dialog.plotInfo.qty == 0 && dialog.OutQtyAllowZero == '0') {
                                                        //如果後 台未設定，不允許出站數量為0 M#80727
                                                        $rootScope.showAlert($filter('translate')('B0206.showAlert.column1'));
                                                    } else {
                                                        multipleCheck(dialog, function(){
                                                            SMES_AccLifeCheck(machine_no, dialog.plotInfo, function(){
                                                                ProductionParametersCheckProcess(dialog);
                                                            });
                                                        });
                                                    }
                                                },
                                                //持續出站
                                                trackOutConfirmContinued: function(){
                                                    if(dialog.plotInfo.qty < dialog.plotInfo.workstation_detail[0].check_out_qty)
                                                        dialog.continued = true;
                                                    if(dialog.isRequire){
                                                        $rootScope.showAlert($filter('translate')('B0206.msg.production_inf_require'), function(){
                                                            dialog.openProductionInfPage();
                                                        });
                                                    } else if(dialog.plotInfo.good_qty < 0) {
                                                        $rootScope.showAlert($filter('translate')('B0206.msg.good_qty_less_than_zero'));
                                                    } else if(dialog.plotInfo.qty == 0 && dialog.OutQtyAllowZero == '0') {
                                                        //如果後 台未設定，不允許出站數量為0 M#80727
                                                        $rootScope.showAlert($filter('translate')('B0206.showAlert.column1'));
                                                    } else {
                                                        multipleCheck(dialog, function(){
                                                            SMES_AccLifeCheck(machine_no, dialog.plotInfo, function(){
                                                                ProductionParametersCheckProcess(dialog);
                                                            });
                                                        });
                                                    }
                                                },
                                                //開啟不良原因
                                                //ADD04 增加傳遞參數 plot_no BY a991241234
                                                openBadPage:function(){
                                                    var content = {
                                                        op_no : dialog.plotInfo.workstation_detail[0].op_no,
                                                        plot_no:dialog.plotInfo.workstation_detail[0].plot_no
                                                    };
                                                    $MMWService.sendToServer({
                                                        uri : 'ServicesSTD.Module_WIP.qc_reason_basis_info_get',
                                                        content : content,
                                                        success : function(data, response){
                                                            //備份
                                                            badReasonInfo_backup = dialog.badReasonInfo.slice();
                                                            dialog.badTypeList = genBadType(data.qc_reason_basis, dialog.badReasonInfo);
                                                            if(dialog.badTypeList.length>0){
                                                                dialog.tmpBadType = dialog.badTypeList[0].reason_type;
                                                            }
                                                            dialog.mode = 'badReason';
                                                            dialog.changeForm('B0206_ExceptionReason');
                                                            dialog.tmpBadReason = {};
                                                            dialog.tmpAbnormal_qty = '';
                
                                                            if(typeof data.smt_reason_basis != 'undefined' && data.smt_reason_basis.length > 0)
                                                            {
                                                                dialog.badReasonInfo.push({
                                                                    plot_no: dialog.plotInfo.workstation_detail[0].plot_no,
                                                                    abnormal_type_name :data.smt_reason_basis[0].reason_sub_type,
                                                                    abnormal_no:data.smt_reason_basis[0].reason_no,
                                                                    abnormal_name:data.smt_reason_basis[0].reason_name,
                                                                    reason_type:data.smt_reason_basis[0].reason_type,
                                                                    defect_qty:data.smt_reason_basis[0].qty
                                                                })
                                                            }
                                                        //     if(!$rootScope.onDevice){//如果在電腦上就啟動鼠標定位
                                                        //         $timeout(function(){
                                                        //             document.querySelector(".searching-bad").focus();
                                                        //         });  
                                                        //     }
                                                        }
                                                    });
                                                },
                                                //增加不良原因到右側已選欄位
                                                //20210615 Modify by德義家興for#90580
                                                add_BadReason_selected: function (item) {
                                                    //在 "出站" 定不良原因 PCSNo 給""值
                                                    if (dialog.mode == 'badReason') {
                                                        dialog.PCSNo = "";
                                                    }
                                                    //檢查該序列號是否有設定不良原因
                                                    var hasBadReason = false;
                                                    dialog.badReasonInfo.forEach(function(item){
                                                        if (item.pcs_no == dialog.PCSNo) {
                                                            hasBadReason = true;
                                                        }
                                                    })
                                                    //在 "序列號收集" 限制只能一個不良原因
                                                    if (dialog.mode == 'newBadReason' && hasBadReason ) {
                
                                                    }else{
                                                        item.chosen = 'Y';
                                                        dialog.badReasonInfo.push({
                                                            reason_type: item.reason_type,
                                                            reason_key: item.key,
                                                            abnormal_type_name: item.reason_sub_type,
                                                            abnormal_no: item.reason_no,
                                                            abnormal_name: item.reason_name,
                                                            defect_qty:0,
                                                            //20210519 Modify by德義家興for#90580
                                                            pcs_no: dialog.PCSNo || '' , //不良原因 產品序列號
                    
                                                        })
                                                    }
                                                    if(!$rootScope.onDevice){//如果在電腦上就啟動鼠標定位
                                                        document.querySelector(".searching-bad").focus();//將焦點移回刷不良原因的條碼欄位。
                                                    }
                                                },
                                                delete_BadReason_selected:function(item){//删除右側已選擇的不良原因
                                                    dialog.badReasonInfo.splice(dialog.badReasonInfo.indexOf(item),1);
                                                    var _type_temp = $filter('filter')(dialog.badTypeList, {reason_type:item.reason_type}, true);
                                                    var _temp = $filter('filter')(_type_temp[0].badReason_list, {reason_no:item.abnormal_no}, true);
                                                    if(_temp.length > 0){
                                                        _temp[0].chosen=undefined;
                                                    }
                                                    if(!$rootScope.onDevice){//如果在電腦上就啟動鼠標定位
                                                        document.querySelector(".searching-bad").focus();
                                                    }
                                                },
                                                clickTypeItem : function(item){//不良原因手風琴
                                                    dialog.tmpBadType = item.reason_type;
                                                },
                                                //QRCode輸入
                                                qrcode_plot_no:function(){
                                                    $rootScope.OpenScanner({
                                                        after : function(result){
                                                            var _item = BadReasonPick(dialog.badTypeList, result.text);
                                                            if(!_item){
                                                                $rootScope.showAlert($filter('translate')('B0206.msg.cont_find_reason')+dialog.tmpBadTypeName);
                                                                dialog.tmpBadTypeName = '';
                                                            } else if(_item.chosen=='Y'){
                                                                $rootScope.showAlert($filter('translate')('B0206.msg.reason_already_exist')+dialog.tmpBadTypeName);
                                                                dialog.tmpBadTypeName = '';
                                                            } else {
                                                                dialog.add_BadReason_selected(_item);
                                                            }
                                                        },
                                                        exception: function(){
                                                            //目前裝置無法使用相機
                                                            $rootScope.showAlert($filter('translate')('B0214.showAlert.column3'));
                                                        },
                                                        orientation : 'landscape'
                                                    });
                                                },
                                                bd_scan:function(event){
                                                    if(event.keyCode == 13){
                                                        if(dialog.tmpBadTypeName ==='ORD_000_A008' && dialog.open_scan_column === true){//確認
                                                            dialog.badReasonConfirm();
                                                            dialog.tmpBadTypeName='';
                                                            $timeout(function(){
                                                                document.querySelector("#tmpBadTypeName").focus();//將焦點移回刷不良原因的條碼欄位。

                                                            });  
                                                        }else if(dialog.tmpBadTypeName ==='ORD_000_A009' && dialog.open_scan_column === true){//關閉
                                                            dialog.trackOutBack();
                                                        }else if(dialog.tmpBadTypeName ==='ORD_000_A012' && dialog.open_scan_column === true){//返回
                                                            dialog.backToTrackOut(dialog);
                                                            dialog.tmpBadTypeName='';
                                                            $timeout(function(){
                                                                document.querySelector("#tmpBadTypeName").focus();//將焦點移回刷不良原因的條碼欄位。

                                                            });   
                                                        }else{
                                                            var _item = BadReasonPick(dialog.badTypeList, dialog.tmpBadTypeName);
                                                            if(!_item){
                                                                $rootScope.showAlert($filter('translate')('B0206.msg.cont_find_reason')+dialog.tmpBadTypeName);
                                                                dialog.tmpBadTypeName = '';
                                                            } else if(_item.chosen=='Y'){
                                                                $rootScope.showAlert($filter('translate')('B0206.msg.reason_already_exist')+dialog.tmpBadTypeName);
                                                                dialog.tmpBadTypeName = '';
                                                            } else {
                                                                dialog.tmpBadTypeName = '';
                                                                dialog.add_BadReason_selected(_item);
                                                            }
                                                        }
                                                       
                                                    }
                                                },
                                                AbnormalQtyAdjust:function(event, item){//調整數量
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,abCalcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        item.defect_qty = (+num);
                                                        if(!$rootScope.onDevice){//如果在電腦上就啟動鼠標定位
                                                                document.querySelector("#tmpBadTypeName").focus();//將焦點移回刷不良原因的條碼欄位。
                                                        }
                                                        abCalcDialog.hide();
                                                    },
                                                    function(abCalcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        abCalcDialog.hide();
                                                    },
                                                    {
                                                        defaultNum : item.defect_qty,
                                                        decimal : true
                                                    });
                                                },
                                                AbnormalUnitQty:function(event, VehicleQty){
                                                    //依照need_vehicle判斷出站是否需要維護載��?
                                                    if(!dialog.plotInfo.fastening_info_detail.vehicle_name
                                                            || dialog.plotInfo.fastening_info_detail.vehicle_name == ''){
                                                        if(dialog.plotInfo.fastening_info_detail.need_vehicle == 2){
                                                            //無維護載具編號，請問是否繼續執行
                                                            $rootScope.showAlert($filter('translate')('B0206.msg.vehicle_info_empty'));
                                                            return;
                                                        }
                                                    }
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        dialog.tmpAbnormal_unit_qty = (+num);
                                                        var _checkout_qty = CaculateFastening(dialog.plotInfo.fastening_info_detail, (+num));
                                                        dialog.tmpAbnormal_qty = _checkout_qty;
                                                        calcDialog.hide();
                                                    },
                                                    function(calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        calcDialog.hide();
                                                    },
                                                    {
                                                        defaultNum : VehicleQty,
                                                        decimal : true
                                                    });
                                                },
                                                //不良原因-確定
                                                badReasonConfirm : function(){
                                                    var total_surplus_qty = 0,//多餘
                                                        total_abnormal_qty = 0, //報廢
                                                        total_lack_qty = 0,//短少
                                                        _QTYACIO = 0,//出站後數量
                                                        _msg = '';
                                                    //20210519 Modify by德義家興for#90580
                                                    //檢查不良原因是在哪裡設定的
                                                    dialog.check_bad_reason();
                
                                                    dialog.badReasonInfo.forEach(function (info) {
                                                        if (info.defect_qty == 0) {
                                                            _msg = $filter('translate')('B0206.msg.badreason_qty_zero');
                                                        } else {
                                                            if(info.reason_type == '11'){
                                                                total_surplus_qty = $calculater.decimalAdd(total_surplus_qty, (+info.defect_qty));
                                                            } else if(info.reason_type == '12'){
                                                                total_lack_qty = $calculater.decimalAdd(total_lack_qty, (+info.defect_qty));
                                                            } else {
                                                                total_abnormal_qty =  $calculater.decimalAdd(total_abnormal_qty, (+info.defect_qty));
                                                            }
                                                        }
                                                    });
                
                                                    if(_msg!=''){
                                                        $rootScope.showAlert(_msg);
                                                        return;
                                                    }
                
                                                    if((total_surplus_qty + dialog.plotInfo.qty)<(total_abnormal_qty+total_lack_qty)){
                                                        $rootScope.showAlert($filter('translate')('B0206.showAlert.column5')+dialog.plotInfo.qty);
                                                    }else{
                                                        dialog.plotInfo.total_surplus_qty = total_surplus_qty;//多餘?
                                                        dialog.plotInfo.total_abnormal_qty = total_abnormal_qty; //不良
                                                        dialog.plotInfo.total_lack_qty = total_lack_qty;//短少
                                                        dialog.plotInfo.good_qty =  $calculater.decimalSub($calculater.decimalSub($calculater.decimalAdd((+dialog.plotInfo.qty), (+dialog.plotInfo.total_surplus_qty)), (+dialog.plotInfo.total_abnormal_qty)), (+dialog.plotInfo.total_lack_qty));
                                                        //2018051601 modify by Dustdusk for M#45925:
                                                        //物料使用��?= 『良品��?+ 『不良品��?+ 『短少��?= 『出站數量��?+ 『多餘��?
                                                        // 20220122 modify by Alan for M#104045: 物料耗用數量計算依系統參數決定是否需計算短少或是多餘的生產數
                                                        var MTL_Includes_ExcessLoss = dialog.plotInfo.MTL_Includes_ExcessLoss === undefined ? true : dialog.plotInfo.MTL_Includes_ExcessLoss;
                                                        // 20231123 modify by wenwei for M#142054: [sMES]物料數量扣減異常[松讚]
                                                        // 物料使用量
                                                        var sum_qty = MTL_Includes_ExcessLoss
                                                            // 良品 + 不良 + 短少 - 多餘
                                                            ? (+plotInfo.good_qty) + (+plotInfo.total_abnormal_qty) + (+plotInfo.total_lack_qty) - (+plotInfo.total_surplus_qty)
                                                            // 良品 + 不良
                                                            : (+plotInfo.good_qty) + (+plotInfo.total_abnormal_qty);
                                                        reCalcMaterialUseQty(sum_qty);
                                                        // 離開例外原因後自動計算出站後生產批數量
                                                        lastqty = plotInfo.workstation_detail[0].CheckOutPlotQty;
                                                        dialog.leftqty = $calculater.decimalSub(
                                                        (+lastqty),
                                                        $calculater.decimalAdd((+dialog.plotInfo.good_qty), (+dialog.plotInfo.total_abnormal_qty))
                                                        );          
                                                        // 20230321 modify by 文蔚 M#130627: 出站報工介面數量為負數
                                                        if (dialog.leftqty < 0 && ($calculater.decimalAdd((+dialog.plotInfo.total_surplus_qty), (+dialog.plotInfo.total_lack_qty)) > 0)) dialog.leftqty = 0
                                                        _QTYACIO = CaculatQTYACIO(dialog.plotInfo.good_qty, dialog.plotInfo.workstation_detail[0].C_Numerator, dialog.plotInfo.workstation_detail[0].C_Denominator);
                                                        if(_QTYACIO != dialog.plotInfo.workstation_detail[0].QTYACIO){
                                                            dialog.plotInfo.workstation_detail[0].QTYACIO = _QTYACIO;
                                                            //多人產量登入
                                                            reCalcMultipleQty(dialog, function () {
                                                                //20210519 Modify by德義家興for#90580
                                                                if (dialog.mode == 'newBadReason') {
                                                                    dialog.mode = 'PCSNo';
                                                                    // 20230303 modify by Alan for M#128535: 補上缺少功能
                                                                    dialog.changeForm('B0206_Serial_Number_Collecte');
                                                                }else{
                                                                    dialog.mode = 'trackOut';
                                                                    dialog.changeForm('B0206');
                                                                }
                                                            });
                                                        } else {
                                                            //20210519 Modify by德義家興for#90580
                                                            if (dialog.mode == 'newBadReason') {
                                                                dialog.mode = 'PCSNo';
                                                                // 20230303 modify by Alan for M#128535: 補上缺少功能
                                                                dialog.changeForm('B0206_Serial_Number_Collecte');
                                                            }else{
                                                                dialog.mode = 'trackOut';
                                                                dialog.changeForm('B0206');
                                                            }
                                                        }
                                                    }
                                                },
                                                //不良原因，取��?
                                                badReasonCancel: backToTrackOut,
                
                                                //進入多人產量登入
                                                openMultiplePage:function(){
                                                    dialog.mode = 'multiple';
                                                    dialog.changeForm("B0206_MutripleOp");
                                                    labor_detail_backup = angular.merge([],dialog.plotInfo.workstation_detail[0].labor_detail);
                                                    if(!$rootScope.onDevice){//如果在電腦上就啟動鼠標定位
                                                        $timeout(function(){
                                                            document.querySelector(".searching-bad").focus();
                                                        });
                                                    }
                                                },
                                                addMultipleLabor: function(labor_no, labor_name){
                                                    var labor_detail = dialog.plotInfo.workstation_detail[0].labor_detail;
                                                    var isExist = false;
                                                    for(var i = 0; i < labor_detail.length; i++){
                                                        if(labor_detail[i].labor_no == labor_no){
                                                            isExist = true;
                                                            break;
                                                        }
                                                    }
                                                    if(!isExist){
                                                        var qty = (dialog.OutQtyOption == '0') ? plotInfo.good_qty : 0;
                                                        labor_detail.push({labor_no: labor_no, labor_name: labor_name, qty: qty, labor_time: 0});
                                                    }else{
                                                        $rootScope.showAlert($filter('translate')('B0206.msg.labor_no_exist', {labor_no: labor_no})); //人員已存��?
                                                    }
                                                    dialog.tmpLabor_no = '';
                                                    getPriceSum();
                                                    getPriceSumByLabor();
                                                    multipleRecalculateImp(dialog, function(){});
                                                },
                                                deleteMultipleLabor: function(item){
                                                    $rootScope.showConfirm($filter('translate')('B0206.msg.is_delete_multiple_labor', {labor_name: item.labor_name}),
                                                        function(confirmDialog){
                                                            confirmDialog.hide();
                                                            var index = dialog.plotInfo.workstation_detail[0].labor_detail.indexOf(item);
                                                            dialog.plotInfo.workstation_detail[0].labor_detail.splice(index, 1);
                                                            getPriceSum();
                                                            getPriceSumByLabor();
                                                            document.querySelector(".value.searching-client").focus();
                                                        }
                                                    );
                                                },
                                                searchLabor: function(event){
                                                    if(!event || event.keyCode==13){
                                                        if(dialog.tmpLabor_no === "ORD_000_A008" && dialog.open_scan_column === true){
                                                            dialog.multipleConfirm();
                                                            $timeout(function(){
                                                                document.querySelector("#tmpBadTypeName").focus();//將焦點移回刷不良原因的條碼欄位。

                                                            });    
                                                            dialog.tmpLabor_no='';
                
                                                        }else if(dialog.tmpLabor_no === "ORD_000_A009" && dialog.open_scan_column === true){
                                                            dialog.trackOutBack();
                                                        }else if(dialog.tmpLabor_no === "ORD_000_A012" && dialog.open_scan_column === true){
                                                            dialog.backToTrackOut(dialog);
                                                            dialog.tmpLabor_no='';
                                                            $timeout(function(){
                                                                document.querySelector("#tmpBadTypeName").focus();//將焦點移回刷不良原因的條碼欄位。
                                                        }); 
                                                        }else{
                                                            if(dialog.tmpLabor_no!=''){
                                                                var content = {
                                                                    machine_no : machine_no,
                                                                    employee_no : dialog.tmpLabor_no,
                                                                    report_datetime : new Date(),
                                                                    return_type : '10'
                                                                };
                
                                                                $MMWService.sendToServer({
                                                                    uri: 'ServicesSTD.Module_SYS.user_information_get',
                                                                    content : content,
                                                                    success : function(data){
                                                                        dialog.addMultipleLabor(data.employee_no, data.employee_name);
                                                                        dialog.tmpLabor_no='';
                                                                        document.getElementById('tmpLabor_no').focus();
                                                                    },
                                                                    error:function(data){
                                                                        $rootScope.showAlert(data.Message, function(){
                                                                            document.getElementById('tmpLabor_no').focus();
                                                                        });
                                                                        dialog.tmpLabor_no='';
                                                                    }
                                                                });
                                                            }else{
                                                                $rootScope.showAlert($filter('translate')('B0206.msg.input_labor_empty'), function(){
                                                                    document.getElementById('tmpLabor_no').focus();
                                                                });
                                                            }
                                                        }
                                                        
                                                    }
                                                },
                                                laborInputQty : function(event, labor){
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,calcDialog){
                                                        var QTYACIO = dialog.plotInfo.workstation_detail[0].QTYACIO;
                                                        if((+num) > (+QTYACIO)){
                                                            $rootScope.showAlert($filter('translate')('B0206.showAlert.column6')+QTYACIO);
                                                            document.getElementById('tmpLabor_no').focus();
                                                        } else {
                                                            calcDialog.hide();
                                                            angular.element(target).removeClass('is-focus');
                                                            labor.qty = num;
                                                            getPriceSumByLabor();
                                                            document.getElementById('tmpLabor_no').focus();
                                                        }
                                                    },
                                                    function(calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        calcDialog.hide();
                                                    },
                                                    {
                                                        defaultNum : labor.qty,
                                                        decimal : true
                                                    });
                                                },
                                                laborInputTime:function(event, labor)
                                                {
                                                    var target = event.currentTarget;
                                                    angular.element(target).addClass('is-focus');
                                                    $calculater.open(function(num,calcDialog){
                                                        calcDialog.hide();
                                                        angular.element(target).removeClass('is-focus');
                                                        labor.labor_time = num;
                                                        getPriceSumByLabor();
                                                        document.getElementById('tmpLabor_no').focus();
                                                    },
                                                    function(calcDialog){
                                                        angular.element(target).removeClass('is-focus');
                                                        calcDialog.hide();
                                                    },
                                                    {
                                                        defaultNum : labor.labor_time,
                                                        decimal : true
                                                    });
                                                },
                                                multipleRecalculate: function(){
                                                    multipleRecalculateImp(dialog, function(){});
                                                },
                                                multipleConfirm:function(){
                                                    multipleCheck(dialog, function(){
                                                        //計算總人��?
                                                        dialog.plotInfo.workstation_detail[0].labor_hours = 0;
                                                        dialog.plotInfo.workstation_detail[0].number_of_labor = 0;
                                                        dialog.plotInfo.workstation_detail[0].labor_detail.forEach(function(labor){
                                                            dialog.plotInfo.workstation_detail[0].labor_hours = $calculater.decimalAdd(dialog.plotInfo.workstation_detail[0].labor_hours, labor.labor_time);
                                                            dialog.plotInfo.workstation_detail[0].number_of_labor += 1;
                                                        });
                                                        dialog.mode='trackOut';
                                                        dialog.changeForm('B0206');
                                                    });
                                                },
                                                multipleCancel:backToTrackOut,
                                                //進入生產資訊收集
                                                openProductionInfPage:function(){  
                                                        dialog.mode = 'production_inf';
                                                        dialog.changeForm("B0206_production_inf_detail");
                                                    if(dialog.plotInfo.production_inf_detail && dialog.plotInfo.production_inf_detail.length>0){
                                                        dialog.mode = 'production_inf';
                                                        dialog.production_inf_detail = dialog.plotInfo.production_inf_detail;
                                                        production_inf_detail_backup = angular.merge([],dialog.plotInfo.production_inf_detail);
                                                    } else {
                                                        $rootScope.showAlert($filter('translate')('B0206.showAlert.production_inf_detail_empty'));
                                                    }
                                                },
                                                switchInit: function(item){
                                                    // 1 文本 2 是否 3数值 	20231120 modify by shiwl for M#0149252: 【厦晖】出站生产信息收集，收集方式为文本型，输入框内会默认带出0
                                                    if(item.method=='2'){
                                                        item.productioninf_value = '0';
                                                    } else {
                                                      item.productioninf_value = '';
                                                    }
                                                },
                                                switchClick: function(item){
                                                    if(item.productioninf_value == '0'){
                                                        item.productioninf_value = '1' ;
                                                    } else {
                                                        item.productioninf_value = '0';
                                                    }
                                                },
                                                productionInfConfirm:function(){
                                                    var msg = '';
                                                    if(dialog.plotInfo.production_inf_type == '2'){
                                                        msg = productionInfValidate(dialog.production_inf_detail);
                                                    }
                                                    if(msg == ''){
                                                        dialog.isRequire = false;
                                                        dialog.mode='trackOut';
                                                        dialog.changeForm('B0206');
                                                    } else {
                                                        dialog.isRequire = true;
                                                        $rootScope.showAlert(msg);
                                                    }
                                                },
                                                //副產��?
                                                OpensubProductPage:function(){
                                                    sub_product_detail_backup = angular.merge([],dialog.plotInfo.sub_product_detail);
                                                    dialog.mode = 'sub_product';
                                                    dialog.changeForm("B0206_Sub_product");
                                                },
                                                subProductConfirm:function(){
                                                    sub_product_detail_backup = [];
                                                    dialog.mode = 'trackOut';
                                                    dialog.changeForm("B0206")
                                                },
                                                // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                                                showLog: function(){
                                                    dialog.logFlag = true;
                                                },
                                                // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                                                leaveLog: function(){
                                                    dialog.logFlag = false;
                                                },
                                                // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                                                clearUseQty: function(){
                                                    dialog.plotInfo.workstation_detail[0].materials_detail.forEach(item => {
                                                        item.use_qty = 0;
                                                    });
                                                },
                                                // 20201214 modify by 外包 for M#83685: 重工批重复扣料多模式选择。
                                                checkReworkType: function(type, outDialog){
                                                    if(btnFlag){
                                                        var msg = $filter('translate')('B0206.msg.msg1');
                                                        if(type == 1){
                                                            $rootScope.showConfirm(msg, function(dialog)
                                                            {
                                                               dialog.hide();
                                                               outDialog.trackOutConfirmContinued();
                                                            });
                                                            return;
                                                        }else if (type == 2){
                                                            $rootScope.showConfirm(msg, function(dialog2)
                                                            {
                                                               dialog2.hide();
                                                               dialog.trackOutConfirm(outDialog);
                                                            });
                                                            return;
                                                        }
                                                    }else{
                                                        if(type == 1){
                                                            outDialog.trackOutConfirmContinued();
                                                        }else if (type == 2){
                                                            dialog.trackOutConfirm(outDialog);
                                                        }
                                                    }
                                                },
                                                //20210519 Modify by德義家興for#90580
                                                //判斷序列號收集功能裡是否有設定不良原因
                                                checkPCSNoBadReasonList: function(){
                                                    if (!dialog.PCSNoHasBadReason || dialog.PCSNoHasBadReason == undefined) {
                                                        dialog.openBadPage();
                                                    }else{
                                                        $rootScope.showAlert($filter('translate')('B0206.msg.The_function_is_enabled'));
                                                    }            
                                                },
                                                //檢查是否有設定原功能的不良原因;只能使用新舊不良原因功能的其中一個
                                                check_original_bad_page: function (item){
                                                    if (dialog.PCSNoHasBadReason || dialog.PCSNoHasBadReason == undefined) {
                                                        dialog.openNewBadPage(item);
                                                    }else{
                                                        $rootScope.showAlert($filter('translate')('B0206.msg.The_function_is_enabled'));
                                                    }
                                                },
                                                //檢查不良原因是在哪裡設定的;時機:在不良原因畫面按確認,在序列號收集畫面刪除PCSNo
                                                check_bad_reason: function(){
                                                    dialog.badReasonInfo.forEach(function(badReason){
                                                        if (!badReason.pcs_no == "") {
                                                            dialog.PCSNoHasBadReason = true;
                                                        }else{
                                                            dialog.PCSNoHasBadReason = false;
                                                        }
                                                    });
                                                    //都沒設定;兩個按鈕都可以操作
                                                    if (dialog.badReasonInfo.length == 0) {
                                                        dialog.PCSNoHasBadReason = undefined;
                                                    }
                                                },
                                                //進入序列號收集
                                                openPCSNo: function(){
                                                    //20221108 modify by 翰鴻 for M#116946
                                                    getPCSNoList(function (list, collected_PCSNo) {
                                                        if (list == undefined) {
                                                            dialog.PCSNoList = [];
                                                            dialog.PCSNoList_count = 0;
                                                            dialog.collected_PCSNo = [];
                                                        }else{
                                                            dialog.PCSNoList = list;
                                                            dialog.PCSNoList_count = list.length;    
                                                            dialog.collected_PCSNo = collected_PCSNo;
                                                        }
                                                    })
                                                    dialog.mode = 'PCSNo';
                                                    dialog.changeForm('B0206_Serial_Number_Collecte');
                                                    if(!$rootScope.onDevice){//如果在電腦上就啟動鼠標定位
                                                        $timeout(function(){
                                                            document.querySelector(".searching-PCSNo").focus();
                                                        });  
                                                    }
                                                },
                                                //QRCode輸入
                                                qrcode_PCSNo: function(){
                                                    $rootScope.OpenScanner({
                                                        after: function (result) {
                                                            check_PCSNo(result.text);
                                                            dialog.tmpPCSNo = "";
                                                            document.querySelector(".searching-PCSNo").focus();
                                                        },
                                                        exception: function () {
                                                            //目前裝置無法使用相機
                                                            $rootScope.showAlert($filter('translate')('B0214.showAlert.column3'));
                                                        },
                                                        orientation: 'landscape'
                                                    });
                                                },
                                                //
                                                enter_PCSNo: function(event){
                                                    if (event.keyCode == 13 && dialog.tmpPCSNo.length != 0) {
                                                        //檢查重複
                                                        dialog.check_PCSNo(dialog.tmpPCSNo);
                                                        dialog.tmpPCSNo = "";
                                                    }
                                                },
                                                //掃碼
                                                insert_PCSNo: function(pcs_no){
                                                    var content = {
                                                        op_no: plot.op_no,
                                                        pcs_no: pcs_no,
                                                        lot_no: plot.plot_no,
                                                        equipment_no: machine.machine_no,
                                                        collection_type: '1', //0=進站, 1=出站
                                                    };
                                                    $MMWService.sendToServer({
                                                        uri: 'ServicesSTD.Module_WIP.serial_num_collecting_check',
                                                        content : content,
                                                        success : function(data){
                                                            if (data.msg.indexOf('error') == -1) {
                                                            }else{
                                                                $rootScope.showAlert($filter('translate')('B0206.msg.Previous_workstation') + data.from_node_no + $filter('translate')('B0206.msg.PCSNo'));
                                                            }
                                                            dialog.openPCSNo();
                                                        }
                                                    });                
                                                },
                                                //檢查重複
                                                check_PCSNo: function(pcs_no){
                                                    var checkStr = '';
                                                    dialog.PCSNoList.forEach(function(item){
                                                        checkStr += item.pcs_no;
                                                    });
                                                    if (checkStr.indexOf(pcs_no) == -1) { //不重複
                                                        dialog.insert_PCSNo(pcs_no);
                                                    }else{
                                                        $rootScope.showConfirm($filter('translate')('B0206.msg.PCSNo_has_been_duplicated'), function (Confirm) {
                                                            Confirm.hide();
                                                            dialog.insert_PCSNo(pcs_no);
                                                        });
                                                    }
                                                },
                                                //刪除PCSNO                                
                                                delete_PCSNo: function(item,all_item){
                                                    $rootScope.showConfirm($filter('translate')('B0206.msg.You_sure_you_want_to_delete_it'), function (Confirm) {
                                                        Confirm.hide();
                
                                                        //判斷是單個刪除還是全部刪除
                                                        var PCSNo = [];
                                                        if (all_item == undefined) {
                                                            PCSNo.push(item.pcs_no);
                                                        }else{
                                                            PCSNo = all_item;
                                                        }
                                                        var content = {
                                                            equipment_no: machine.machine_no,
                                                            lot_no: plot.plot_no,
                                                            op_no: plot.op_no,
                                                            collection_type: "1", //0=進站, 1=出站
                                                            pcs_no: PCSNo,
                                                        };
                                                        $MMWService.sendToServer({
                                                            uri: 'ServicesSTD.Module_WIP.delete_serial_num_process',
                                                            content : content,
                                                            success : function(data){
                                                                if (all_item == undefined) {
                                                                    //刪除該pcsno對應的badReasonInfo
                                                                    dialog.badReasonInfo = dialog.badReasonInfo.filter(function(badReason){
                                                                        return badReason.pcs_no != item.pcs_no;
                                                                    });
                                                                }else{
                                                                    //清空badReasonInfo
                                                                    dialog.badReasonInfo.splice(0, dialog.badReasonInfo.length);
                                                                }
                                                                //檢查不良原因是在哪裡設定的
                                                                dialog.check_bad_reason();
                                                                dialog.openPCSNo();
                                                            }
                                                        });
                                                    });
                                                },
                                                //刪除所有
                                                delect_all_PCSNo: function(){
                                                    if (dialog.PCSNoList.length > 0) {
                                                        var arr_PCSNo = [];
                
                                                        dialog.PCSNoList.forEach(function(item){
                                                            arr_PCSNo.push(item.pcs_no);
                                                        });
                                                        dialog.delete_PCSNo(undefined,arr_PCSNo);
                                                    }
                                                },
                                                //開啟不良原因
                                                openNewBadPage: function (item) {
                                                    //20210519 Modify by德義家興for#90580 
                                                    //開啟例外原因時 帶入個別產品序列號
                                                    dialog.PCSNo = item.pcs_no;
                                                    dialog.PCSNoBadReasonList = [];
                                                    //抓出屬於這個pcsno的badReasonInfo
                                                    dialog.badReasonInfo.forEach(function(badReason){
                                                        if (badReason.pcs_no == item.pcs_no) {
                                                            dialog.PCSNoBadReasonList.push(badReason);
                                                        }
                                                    });
                
                                                    var content = {
                                                        op_no: dialog.plotInfo.workstation_detail[0].op_no,
                                                        plot_no: dialog.plotInfo.workstation_detail[0].plot_no
                                                    };
                                                    $MMWService.sendToServer({
                                                        uri: 'ServicesSTD.Module_WIP.qc_reason_basis_info_get',
                                                        content: content,
                                                        success: function (data, response) {
                                                            //備份
                                                            badReasonInfo_backup = dialog.badReasonInfo.slice();
                
                                                            dialog.badTypeList = genBadType(data.qc_reason_basis, dialog.PCSNoBadReasonList);
                
                                                            if (dialog.badTypeList.length > 0) {
                                                                dialog.tmpBadType = dialog.badTypeList[0].reason_type;
                                                            }
                                                            dialog.mode = 'newBadReason';
                                                            // 20230303 modify by Alan for M#128535: 補上缺少功能
                                                            dialog.changeForm('B0206_ExceptionReasonForSerialNo')
                                                            dialog.tmpBadReason = {};
                                                            dialog.tmpAbnormal_qty = '';
                                                            //目前用不到
                                                            if (typeof data.smt_reason_basis != 'undefined' && data.smt_reason_basis.length > 0) {
                                                                dialog.badReasonInfo.push({
                                                                    plot_no: dialog.plotInfo.workstation_detail[0].plot_no,
                                                                    abnormal_type_name: data.smt_reason_basis[0].reason_sub_type,
                                                                    abnormal_no: data.smt_reason_basis[0].reason_no,
                                                                    abnormal_name: data.smt_reason_basis[0].reason_name,
                                                                    reason_type: data.smt_reason_basis[0].reason_type,
                                                                    defect_qty: data.smt_reason_basis[0].qty
                                                                })
                                                            }
                                                            if(!$rootScope.onDevice){//如果在電腦上就啟動鼠標定位
                                                                $timeout(function(){
                                                                    document.querySelector(".searching-bad").focus();
                                                                });  
                                                            }
                                                        }
                                                    });
                                                },
                                                //序列號收集 確認紐
                                                PCSNoConfirm: function(){
                                                    if (dialog.PCSNoList_count >= 1) {
                                                        dialog.update_PlotInfo_Qty();
                                                    }
                                                    dialog.mode = 'trackOut';
                                                },
                                                //更新dialog.plotInfo.qty;進站數量
                                                update_PlotInfo_Qty: function(){
                                                    dialog.plotInfo.qty = dialog.PCSNoList_count;
                                                    dialog.badReasonConfirm();
                                                },
                                                //20221108 add by 翰鴻 for M#116946
                                                openCollectedPCSNo: function () {
                                                    dialog.mode = 'collectedPCSNo';
                                                },
                                                PCSNoBack: function () {
                                                    dialog.mode = 'PCSNo';
                                                },
                                                collectedPCSNo_back: function () {
                                                    dialog.mode = 'PCSNo';
                                                }
                                            };
                                        }
                                    );
                        })
                      
                    };
    
                    // 20211007 modify by Jason for M#0092955: [懋莉工業] 生產參數設定異常良率觸發後，無後續功能
                    //異常良率強制出站
                    function CheckOutDialog(parent_dialog){
                        $mdDialog.dialog(
                            'module/moduleB/program/B02/B0206/B0206.password.html',
                            function(dialog){
                                return {
                                    css_url:'module/moduleB/program/B02/B0206/B0206.password.css',
                                    account: '',
                                    password: '',
                                    type: '',
                                    ic_card: '',  //IC卡
                                    beforeShown: function(){
    
                                    },
                                    showPassword: function(id){
                                        if(document.getElementById(id).type == 'password'){
                                            document.getElementById(id).type = 'text';
                                            dialog[id+'_show'] = true;
                                        } else {
                                            document.getElementById(id).type = 'password';
                                            dialog[id+'_show'] = false;
                                        }
                                    },
                                    ICCardScanner: function () {//20200723 add by linzh for M#71988
                                        $rootScope.OpenScanner({
                                            after: function (result) {
                                                $timeout(function () {
                                                    dialog.ic_card = result.text;
                                                    dialog.searchICCard();
                                                });
                                            },
                                            exception: function () {
                                                //目前裝置無法使用相機
                                                $rootScope.showAlert($filter('translate')('B0214.showAlert.column3'));
                                            },
                                            orientation: 'landscape'
                                        });
                                    },
                                    searchICCard: function (event) {//20200710 add by linzh for M#71988
                                        if (!event || event.keyCode == 13) {
                                            if (dialog.ic_card != '') {
                                                var content = {
                                                    IcNo: dialog.ic_card
                                                }
                                                $MMWService.sendToServer({
                                                    uri: 'ServicesSTD.Module_SYS.ic_card_info_get',
                                                    content: content,
                                                    success: function (data) {
                                                        if (data.UserNo != null && data.PassWord != null) {
                                                            dialog.account = data.UserNo;
                                                            dialog.password = data.PassWord;
                                                        }
                                                        else {
                                                            $scope.$root.showAlert($filter('translate')('Login.error.ic_card_error'));
                                                        }
                                                    },
                                                    error: function (data) {
                                                        $rootScope.showAlert(data.Message);
                                                        dialog.ic_card = '';
                                                        document.getElementById('ic_card').focus();
                                                    }
                                                });
                                            } else {
                                                $rootScope.showAlert($filter('translate')('B0202.showAlert.column7'));
                                                dialog.ic_card = '';
                                                document.getElementById('ic_card').focus();
                                            }
                                        }
                                    },
                                    back: function () {
                                        dialog.hide();
                                    },
                                    //出站
                                    checkout: function () {
                                        var msg = '';
    
                                        if(dialog.account == ''){
                                            msg += $filter('translate')('B0231.password.msg.account_empty');
                                        } else if(dialog.password == ''){
                                            msg += $filter('translate')('B0231.password.msg.password_empty');
                                        }
    
                                        if(msg == ''){
    
                                            parent_dialog.force_check_out=true;
                                            parent_dialog.force_account=dialog.account;
                                            parent_dialog.force_password=dialog.password;
                                            //出站
                                            trackOutConfirm(parent_dialog,dialog);
                                        } else {
                                            $rootScope.showAlert(msg);
                                        }
                                    },
                                    //暫停
                                    plotwait: function(){
                                        SMES_PlotWaitSetProcess(dialog)
                                        dialog.hide();
                                        parent_dialog.hide();
                                    }
                                };
                            }
                        );
                    }
    
                    //生產批暫停
                    function SMES_PlotWaitSetProcess(dialog) {
    
                        SMES_PlotWaitInfoGet(function(data){
                            if(data.lot_state_curqty)
                                plot.lot_state_curqty = data.lot_state_curqty;
                            else
                                plot.lot_state_curqty = 0;
                            if(data.equipment_input_qty)
                                plot.equipment_input_qty = data.equipment_input_qty;
                            else
                                plot.equipment_input_qty = 0; 
    
                                var content={
                                    op_no: plot.op_no,
                                    equipment_no: machine_no,
                                    plot_no: plot.plot_no,
                                    working_type: 1,
                                    qty: plot.qty,//dialog.plotInfo.qty,
                                    plot_stamp:plot.plot_stamp,
                                    status : plot.status,
                                    rework_flag:0,
                                    lot_state_curqty:plot.lot_state_curqty,
                                    equipment_input_qty:plot.equipment_input_qty,
                                    wait_reason_detail:[]
                                };
            
                                //暫停原因寫死Z901，異常良率
                                content.wait_reason_detail.push({reason_no:'Z901'});
           
    
                                $MMWService.sendToServer({
                                    uri : 'ServicesSTD.Module_WIP.plot_wait_set_process',
                                    content : content,
                                    success : function(data){
                                        $rootScope.showToast($filter('translate')('B0208.msg.success'));
                                        dialog.hide();
           
                                        if(feedback)
                                        feedback();
                                    }
                                });
                        });
    
                    }
    
                    function SMES_PlotWaitInfoGet(callback){
                        var content={
                            op_no: plot.op_no,
                            plot_no: plot.plot_no,
                            trigger_point: '0', //0 (暫停), 1 (解除暫停)
                            machine_no: plot.machine_no,
                            status: plot.status
                        };
                        $MMWService.sendToServer({
                            uri : 'ServicesSTD.Module_WIP.plot_wait_info_get',
                            content : content,
                            success : function(data){
                                if(callback)
                                    callback(data);
                            }
                        });
                    }
    
                    //20220511 add by 翰鴻 for M#102965、110964 换刀批量产品出站后自动进入上下具界面
                    function changeBladeCheckAndLoadAccessory(plot_no, op_no)
                    {
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.check_change_blade_lot_info_get',
                            content: {
                                plot_no: plot_no,
                                op_no: op_no
                            },
                            success: function (data) {
                                if (data.isChangeBladeLot)
                                {
                                    //当前出站生产批为换刀批量，请换刀具
                                    $rootScope.showAlert($filter('translate')('B0206.showAlert.please_change_blade'));
                                    $mdDialog.serviceDialog('B0221Service', {
                                        parent: "B0206",
                                        machine: machine,
                                        //20221014 add by 翰鴻 for M#118366
                                        ProductList: Array.from(productList),
                                        callback: function () {
                                            dog.bark();
                                        }
                                    });
                                }
                            }
                        });
                    }
    
                    //20210519 Modify by德義家興for#90580
                    isPlugInEqualFive();
                  
    
                    getInitInfo();
                   
                };
            }]);
    });
    